Hi scripters!
This is my first attempt at writing an applescript. I have used other peoples scripts plus the example scripts as inspiration.
The purpose of the script is to update my Facebook Status with the name, artist and album of the song being currently played in Itunes. The status update is achieved by sending an email to the address that Facebook provides each user.
So I grab the info from iTunes and then create a mail message, before sending I display a dialogue box with the status update and a choice whether to send the mail or not.
When I choose not to send the message the draft mail window is shown with the dialogue box asking if I want to save the draft, cancel or not save.
If I have the new message invisible and choose not to send the mail it is automatically saved in the draft folder.
Is there any way of telling Mail not to save the draft when issuing the delete command?
Here is my script.
tell application "iTunes"
if it is running then
try
set playerstate to (get player state)
end try
if playerstate = paused then
set trackPaused to " (paused)"
else
set trackPaused to ""
end if
if playerstate = stopped then
return "Stopped"
end if
set this_name to the name of current track
if this_name is "" then set this_name to "Unknown"
set this_album to the album of current track
if this_album is "" then set this_album to "Unknown"
set this_artist to the artist of current track
if this_artist is "" then set this_artist to "Unknown"
set cr to ASCII character 13
set totalData to "♫ I am listening to '" & this_name & trackPaused & "' by '" & this_artist & "' from the album '" & this_album & "' ♫"
else
"No music at the moment"
end if
set theName to "Facebook"
set theAddress to "XXXXXXXXXX@m.facebook.com"
set theSubject to totalData
set theSender to "YYYYYYYYY@gmail.com"
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject}
tell newMessage
-- Default is false. Determines whether the compose window will
-- show on the screen or whether it will happen in the background.
set visible to true
set sender to theSender
make new to recipient at end of to recipients with properties {name:theName, address:theAddress}
set send_q to display dialog "Would you like to update your Facebook status to your current iTunes song?" default answer totalData buttons {"No", "Send"} default button 1 with title "Update FB Status"
if button returned of send_q is not equal to "Send" then
delete newMessage
end if
activate
send
end tell
end tell
return totalData
end tell
Any suggestions on improving the script would be appreciated.
Like being able to define theAddress and theName in preferences so they are not hard coded, getting it to run in the background and pop up when the song changes (how annoying would that be!!?)
Thanks