Skip to content

Instantly share code, notes, and snippets.

@openfirmware
Created December 19, 2010 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save openfirmware/747804 to your computer and use it in GitHub Desktop.
Save openfirmware/747804 to your computer and use it in GitHub Desktop.
Return iTunes Selection
(*
Return the quoted paths of the currently selected tracks in iTunes
Returns error if iTunes is not running
Call from command line with 'osascript -e itunes_selection.scpt'
*)
on run
tell application "System Events"
if (name of processes) contains "iTunes" is false then
return "Error: iTunes is not running"
end if
end tell
set paths to {}
tell application "iTunes"
set sel_list to selection of window 1
repeat with i from 1 to (number of items of sel_list)
set sel to (item i of sel_list)
set ppath to POSIX path of file (location of sel as string)
set paths to paths & quoted form of ppath
end repeat
end tell
set AppleScript's text item delimiters to ASCII character 10
paths as text
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment