Place random image in Messages with Applescript - TextExpander

Discussion in 'Mac Programming' started by YSR50, Jul 11, 2014.

  1. YSR50 macrumors newbie

    YSR50

    Joined:
    Sep 13, 2004
    #1
    Posted this over in the Apple Support Communities but thought I'd have a better chance at a reply here.

    I've been using Apple computers since '84 but I've never used Appplescript and was hoping for some help.

    I'd like to be able to place a random image in Messages with an Applescript through TextExpander. When I type my snippet into Messages the Finder will open a random image from a folder using something like this:

    Code:
    tell application "Finder"
    set randomImage to some file of folder "Mac HD:Users:me:photos:chat pics"
    get randomImage
    open randomImage
    end tell
    If I replace "Finder" with "Messages" it doesn't work. Do I need to combine 2 Applescripts to make this happen?

    TIA
     
  2. numero macrumors regular

    Joined:
    Jul 23, 2002
    Location:
    OR
    #2
    This was a fun one. I didn't know TextExpander existed.

    Change the location of your folder of random images and you should be good to go.

    Code:
    tell application "Finder"
    	set randomFile to (some file of folder "Macintosh HD:Users:numero:Desktop:random:")
    	set the clipboard to (randomFile as «class furl»)
    end tell
    
    
    tell application "Messages"
    	tell application "System Events"
    		keystroke "v" using command down
    		key code 36 -- This is a 'return'. Remove if you don't want the message to be automatically sent.
    	end tell	
    end tell
     
  3. YSR50 thread starter macrumors newbie

    YSR50

    Joined:
    Sep 13, 2004

Share This Page