Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

YSR50

macrumors newbie
Original poster
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
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.