Skip to content

Instantly share code, notes, and snippets.

@itsdamslife
Created August 16, 2012 10:55
Show Gist options
  • Save itsdamslife/3369260 to your computer and use it in GitHub Desktop.
Save itsdamslife/3369260 to your computer and use it in GitHub Desktop.
Saving information in plist through Applescript (In example: current track played in iTunes)
tell application "System Events"
tell application "iTunes"
set mytrack to name of current track
set myalbum to album of current track
set myartist to artist of current track
end tell
-- create an empty property list dictionary item
set the parent_dictionary to make new property list item with properties {kind:record}
-- create new property list file using the empty dictionary list item as contents
set the plistfile_path to "~/Documents/example.plist"
set pl to ¬
make new property list file with properties {contents:parent_dictionary, name:plistfile_path}
-- add the values to plist
tell pl
-- create a text entry
make new property list item at end with properties ¬
{kind:string, name:"album", value:myalbum}
make new property list item at end with properties ¬
{kind:string, name:"artist", value:myartist}
make new property list item at end with properties ¬
{kind:string, name:"track", value:mytrack}
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment