AppleScript to download the highlighted image from Safari

Hello. I am trying to write a script not to do something different that I am personally unable to perform, but rather to remove the necessity on my part for doing several repetitive tasks. I could probably do this in Automator, but I want to do it in Applescript, because I will more easily be able to manipulate it later.

I want just basically want to download an image that I highlight or select. Plain and simple. Nothing fancy for now, I just want to save the image to my computer. Thanks in advance for the help!

Right mouse click and choose Save Image As from the contextual menu.

As Craig says.

Unless you mean you want to save it some other place than your downloads folder, and do not want to navigate around the dialogue windows.

More details would help if that is the case. And maybe some cane help if you still not found what you are looking for.

Actually, that is what I wanted to do… I want to save them to a folder other than my downloads folder… how do I do that? Or is it just a matter of writing the scripts to navigate the dialog? cuz I can do that, but I just wanted to know if there was a solely code way of doing it?

I think you maybe able to do it with javascript, but I have not worked it out yet…

Example, you can grab the selected text.

tell application "Safari"
set selectedText to (do JavaScript "(getSelection())" in document 1)
end tell

But that does not work on images. so still looking:)

a work-around is to place a droplet in your Dock.
then drag & drop an image from Safari on to the droplet.
that should place it in a folder named (by you) ‘Downloaded Images’ within your Documents folder.

on run
	tell me to display dialog "Please don't click on me." & return & "I'm an AppleScript droplet." & return & ¬
		"Only drag and drop a file on me." buttons {"OK"} default button 1 cancel button 1 with icon stop
end run

on open (sourceFile)
	tell application "Finder"
		set home_path to home as text
		set the_folder to (home_path & "Documents:Downloaded Images:")
		set newFile to duplicate sourceFile to the_folder with replacing
		delay 0.5
		-- downloaded images will cache - the line below will delete them.
		do shell script "rm -rf ~/Library/Caches/TemporaryItems/*"
	end tell
end open

Tom

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Why not just do it the Apple way. Drag & Drop
Open the folder you want and then just Drag & Drop image into preferred folder.

Just a note on this. There is a bug in Mac OS that, for me, makes dragging an image to the deskto fail about 30% of the time. On all systems, Mac Pro and Macbook Pro (two different ones), since 10.5.x. Dragging some images will just not be seen by the OS, and I’ll have to manually right click them. Among other things, this makes Google Chrome’s ugly download bar pop up which I then have to close. So i am happy to have some other options too.

Google Chrome you say? Maybe (probably) then, it’s a big in Google’s application, not in the Finder.