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"
return
end if
end repeat
Check Input As Numbers Only Using Array
18 11 2007Comments : Leave a Comment »
Categories : AppleScript
Write To File As UTF-8
10 11 2007set 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)
Comments : Leave a Comment »
Categories : AppleScript
Run Applescript in Carbon
7 11 2007Found in Apple Developer Connection
Example
SimpleRunAppleScript(
"tell application \"Finder\"\n"
" activate\n"
" select folder \"Documents\" of startup disk\n"
" open selection\n"
"end tell");
Comments : 2 Comments »
Categories : AppleScript, C++
Get Root Path
7 11 2007set rootpath to path to startup disk as string
display dialog rootpath
Comments : Leave a Comment »
Categories : AppleScript
Auto. Create & Save TextEdit File
3 11 2007set 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
Comments : 1 Comment »
Categories : AppleScript
Minimize All Safari Windows
1 11 2007tell 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
Comments : Leave a Comment »
Categories : AppleScript
Get Default Browser
1 11 2007Does not work in Leopard
set bundleID to do shell script "defaults read com.apple.LaunchServices | grep -A5 \"http\""
if bundleID contains "com.apple.safari" then
tell application "Safari" to activate
else if bundleID contains "org.mozilla.firefox" then
tell application "Firefox" to activate
end if
Comments : Leave a Comment »
Categories : AppleScript
Display Dialog
1 11 2007Displays dialog with 2 buttons
display dialog "How are you?" buttons {"Good", "Sucks"} default button 1 with icon 1
Display dialog with text box
set question to display dialog "Enter your name" default answer "" buttons {"OK", "Close"} default button 1 with icon 1
set selectedButton to button returned of question
set strName to text returned of question
if selectedButton is equal to "OK" then
display dialog "Hello " & strName
end if
Comments : Leave a Comment »
Categories : AppleScript
Launch Application using Finder
1 11 2007Useful when location of application is unknown (or just can’t be arsed to find it
)
tell application "Finder"
tell application NameOfMyApp to activate
end tell
Comments : Leave a Comment »
Categories : AppleScript
Launch Website & Add Text Into Textbox
1 11 2007tell application "Safari"
--activate to bring Safari to the front--
activate
try
--check if Safari is already open --
set currentDoc to the document of window 1
on error NSReceiverEvaluationScriptError
set currentDoc to make new docuent
end try
set the URL of currentDoc to "http://www.google.com"
-- or use--
open location "http://www.google.com"
--delay for page to load--
delay 2
--use javascript to enter text into textbox
set thisscript to "document.forms[0].q.value='applescript';"
do JavaScript thisscript in document 1
end tell
Comments : Leave a Comment »
Categories : AppleScript, Javascript