How to get Safari to save a page

I’ve tried all kinds of techniques and nothing works. I can’t even get it to do it like this:

tell application “System Events” to tell process “Safari”
activate
keystroke “s” using command down
End tell

That does nothing but open the save window in script editor.

Thanks.

Ofcourse. That is because Script Editor is your active appliecation and when you press Cmd+S, only the save window opens.

tell application "Safari" to activate
tell application "System Events"
	tell process "Safari"
		keystroke "s" using command down
		delay 0.2
		keystroke return
	end tell
end tell

I probably should have seen that :slight_smile:

So then this is what I have so far.

set the target_URL to "http://jott.com/notes.aspx?page=243"
set the destination_file to "Macintosh HD:Users:jeffrey:Downloads:jotts:" & "243.txt"
tell application "Safari" to activate
open location target_URL
delay 5
tell application "System Events"
	tell process "Safari"
		keystroke "s" using command down
		delay 0.2
		keystroke return
	end tell
end tell

What this doesn’t do is allow me to change the name of the file. Is there a way to insert some text into the filename field before pressing the save button?

Thanks again.

activate application "Safari"
tell application "System Events"
	tell process "Safari"
		click menu item "Save As." of menu 1 of menu bar item "File" of menu bar 1
		delay 0.2
		set value of text field 1 of sheet 1 of window 1 to "FileName"
		click button "Save" of sheet 1 of window 1
	end tell
end tell

Hi, Craig–

Thanks :slight_smile: