Mailsmith
Other Programs
Scripts
Mailsmith.scpt
Archive to sub-mailbox
Check Spelling
Find reply
Change font size
Submit Script to JEM
Fix common spelling errors
Setting SMTP server
URL from Safari
Address from AB
linkMunge
Export to Address Book
Saving attachments
Digest Script
File with same
POP window position
Position of new windows
iCal and Mailsmith
Edit From Line
Modified Thread Script
Reply to Selection
Temporary Text Window
Compact gain
Tracking backups
Edit subject
Googler
Auto-rewrap
MMA
SMTP server
Open, fetch, and close
URL Manager
BrainForest
Thread by Author
Thread by subject
Export Email
Get Selection
Read Addresses
Export Email
Organize Email
Account setup
Mailsmith 2 BBEdit
BBEdit 2 Mailsmith
Search II
Check One
Delete Enclosure
Open, fetch, close
Set Answered
Set Redirected
Empty Trash
List found
Print Several
Del. old. msg.
Delete Enclosures
Accounts
Address Book
Editing
Filters
General
Import/Export
Links
Mailboxes
Memory
Scripting
Speed
send/receive
Tips/Tricks


linkMunge - Signature

Author Terje Bless
Last modified 2003-02-21
What is this?

From the "Insanely Complicated Signature Department":

l i n k M u n g e - S i g n a t u r e

Attached to Mailsmith's Message€Send Now menu, if iTunes is running and currently playing a song it will get the song's title, artist, and album, and append the info to the .sig when you send the message. If iTunes isn't running or isn't currently playing it will choose a .sig randomly from your Mailsmith "Random Signatures" file (which must exist and have at least one .sig BTW, I couldn't be bothered to make the script smarter just now).

Save in "~/Library/Application Support/Mailsmith Support/Menu Scripts/" as "Message€Send Now" and relaunch Mailsmith.

The script will only run when you choose "Send Now" from the "Message" menu or hit whatever keyboard command you have assigned to that command (Cmd-E by default IIRC). Notably, it will *NOT* run when you click the "Send" button in a Message Window! Not my fault; go bug BBSW Support about it! :-)


property _Signatures : {}

on menuselect(menuName, itemName)
  if _Signatures = {} then set _Signatures to my readSigs()
  
  if menuName = "Message" and itemName = "Send Now" then
    -- Check that iTunes is running and get the info.
    tell application "System Events"
      set _procs to every process whose name is "iTunes"
      if (count of items in _procs) = 0 then
        set _Signature to my getSig() -- iTunes isn't running...
      else
        tell application "iTunes"
          if player state is not playing then
            -- iTunes is Paused, Stopped, etc.
            set _Signature to my getSig()
          else
            set _s to "Now Playing "
            set _s to _s & "\"" & current track's name & "\""
            set _s to _s & " by \"" & current track's artist & "\""
            set _s to _s & "\", from the album \"" & ¬
              current track's album & "\"." & return
            set _Signature to _s
          end if
        end tell
      end if
    end tell
    
    -- Set up the Signature...
    set theSig to return & return & "-- " & return -- Signature separator.
    set theSig to theSig & _Signature
    
    -- Add the .sig to the end of the message.
    tell application "Mailsmith"
      tell window 1
        select insertion point after last line
        set selection to theSig
      end tell
    end tell
  end if -- Invoked from the wrong menu item...
  return false
end menuselect

on postmenuselect(menuName, itemName)
  set _Signatures to my readSigs()
  return false
end postmenuselect

on getSig()
  set i to random number from 1 to ((count of items in _Signatures) + 1)
  set _sig to item i of _Signatures
end getSig

on readSigs()
  set _sigfile to path to application support from user domain as string
  set _sigfile to _sigfile & "Mailsmith Support:Random Signatures"
  set _sighandle to open for access file _sigfile
  set _sigs to read _sighandle using delimiter return as list
  close access _sighandle
  
  set theSig to ""
  set mySigs to {}
  set _seen to false
  repeat with i from 1 to count of items in _sigs
    set _line to item i of _sigs
    --  display dialog _line
    if _line is "-- " then
      if _seen is true then
        set mySigs to mySigs & theSig
        set theSig to ""
      else
        set _seen to true
      end if
    else
      set theSig to theSig & _line & return
    end if
  end repeat
  return mySigs
end readSigs