Check Input As Numbers Only Using Array

18 11 2007

set numList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
repeat with myCounter from 1 to (length of serialNo)
set myChar to item myCounter of serialNo
if myChar is not in numList then
display dialog "Please enter numbers only." buttons {"OK"} default button 1 with icon "iconWarning"
end if
end repeat


Write To File As UTF-8

10 11 2007

set thePath to ":Library:Application Support:MyApp:test.txt"
write "Hello World" to file thePath as «class utf8»

If you get an Expected expression but found unknown token. (-2741) error, just change your applescript file format. Format -> File Encoding -> Western (MacRoman)

Run Applescript in Carbon

7 11 2007

Found in Apple Developer Connection


"tell application \"Finder\"\n"
" activate\n"
" select folder \"Documents\" of startup disk\n"
" open selection\n"
"end tell");

Get Root Path

7 11 2007

set rootpath to path to startup disk as string
display dialog rootpath

Auto. Create & Save TextEdit File

3 11 2007

set folderpath to "Macintosh HD:Users:Phoenix:test:"
tell application "TextEdit"
set myDoc to document 1
set text of myDoc to "Hello World"
set filepath to folderpath & "hello.txt"
close myDoc saving yes saving in filepath
end tell

Minimize All Safari Windows

1 11 2007

tell application "Safari"
set allWindows to get windows
set n to count allWindows
repeat until n = 0
set miniaturized of window n to true
set n to n - 1
end repeat
end tell

Get Default Browser

1 11 2007

Does not work in Leopard

set bundleID to do shell script "defaults read | grep -A5 \"http\""
if bundleID contains "" then
tell application "Safari" to activate
else if bundleID contains "org.mozilla.firefox" then
tell application "Firefox" to activate
end if