Quick Applescripts

I’ve toyed with AppleScript for years now, usually just to do weird things that aren’t easily accessible like automating iTunes Music Store contest entries, setting the desktop automatically. You know, generally useless things that at the time, present themselves as minor challenges that I must solve.

Here are a few quick AppleScripts for you that I use on a regular basis.

Get the file path of the selected item in the Finder. (does not work with multiple selections)


on run
tell application "Finder"
set selectedItem to (item 1 of (get selection))
set infoList to {}
(* copy ("Displayed Name: " & displayed name of selectedItem) to end of infoList
copy ("Kind: " & kind of selectedItem) to end of infoList
copy ("Size: " & size of selectedItem & " (" & physical size of selectedItem & ")") to end of infoList
copy ((selectedItem as alias) as string) to end of infoList
copy ("Created: " & creation date of selectedItem) to end of infoList
copy ("Modified: " & modification date of selectedItem) to end of infoList
copy ("Name & Extension: " & name of selectedItem) to end of infoList
copy ("Locked: " & locked of selectedItem) to end of infoList
copy ("Comments: " & comment of selectedItem) to end of infoList
copy ("Owner: " & owner of selectedItem) to end of infoList
copy ("Group: " & group of selectedItem) to end of infoList *)
end tell
set {od, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}
set infoAsString to infoList as string
set AppleScript's text item delimiters to od
set the clipboard to infoAsString
return infoAsString
end run

Here’s one that I didn’t write but is alot of fun with Expose. If you want to call one of the Exposé functions from an AppleScript, you can do the following (Note: This script assumes you have the default Exposé key bindings; if you’ve changed them, this will not work as expected!):


-- All windows
tell application "System Events" to key code 101
-- Application windows
tell application "System Events" to key code 109
-- See desktop
tell application "System Events to key code 103
-- See desktop in slow motion
tell application "System Events" to key code 103 using shift down

For example, you can freak out people with this 🙂


tell application "System Events"
set ap to 109
set desk to 103
set win to 101
repeat with a in ¬
{ap, desk, win, win, desk, ap, desk, ap, ap, ¬
ap, desk, win, ap, desk, desk, win, ap, desk, desk}
key code a
end repeat
end tell

Just copy and paste into the AppleScript Script Editor and have fun.