Hayne of Tintagel
AppleScripts
This page provides some
AppleScripts
that I have written.
- announceMail
If you add a rule in
Mail.app's
preferences to invoke this AppleScript,
Mail.app will announce the subject and sender of each incoming mail message
using whatever text-to-speech voice has been specified
in your OS X Speech preferences.
- copyWithoutXAttr
Files on OS X can have resource forks and other extended attributes and
as of Tiger (10.4) the 'cp' command copies these extended attributes.
This AppleScript droplet copies files to a specified destination
but suppresses the copying of extended attributes.
This is useful when the destination is on a non-HFS volume
in order to avoid the "._" files that would otherwise be produced.
The "heavy lifting" is done via a Perl script:
copy_without_xattr
Illustrates several useful AppleScript techniques:
- handling the files dropped on an AppleScript droplet
- a separate handler that gets invoked when the droplet is double-clicked
- converting filepaths from traditional Macintosh colon-separated format
(as used in AppleScript) to standard Unix slash-separated format
for use with 'do shell script'
- appInfoInTitle
Displays the amount of memory being used by designated apps (e.g. Safari)
in the titles of their frontmost windows.
It also displays the app's CPU usage if it exceeds 10%.
And it pops up a warning dialog if the app's memory usage exceeds a specified
amount.
Illustrates several useful AppleScript techniques:
- the use of an idle handler
- subroutines with labeled parameters
- creating instances of script objects on the fly
- getting & setting properties of script objects
- getting the number of seconds since a previous event
- removing the last part of a string
- embedding a multi-line Perl script in an AppleScript
by ensuring that it gets the correct (Unix-style) line endings
- use of the Growl tool for warnings
- testEmbeddedStrings
Tests the behaviour of embedded text strings with regard to end-of-line
characters (See the
"end-of-line characters" section in my Unix FAQ).
Illustrates several useful AppleScript techniques:
- converting a string to have Unix-style line endings
- prompting the user for a filename when saving a file
- writing text to a file
- showEnvVars
Shows the execution environment (environment variables and current folder)
of GUI apps in OS X. (Run this script from Script Editor or save it as an
application and then run it via double-click in Finder.)
- runConsoleAsAdmin
Runs the "Console" application as the admin user specified in the script.
Provides a 'runAsUser' handler that could be used to run any executable
as a specified user.
When this script is run, you are asked for your admin password,
and then the Console app runs as the user specified in the script.
- See also the Bash script
'fixAppleScriptApp'
that changes the application bundle of a compiled AppleScript
(one that has been saved as an application bundle)
so that the application name is used instead of "applet".