Photoshop autosave scripting help

Hi I was wondering if anyone would be kind enough to help me with my scripting problem. I found this script for Photoshop CS 2. I want to not just be able to get a save option reminder but I would like it to save it as a back up file seperate from the one I am working on. For now this script just replaces the same file. I really need a solution to this because I spent all day at work working on photoshop for a deadline and the project crashed corrupting my psd file. If I had a back up it would save me a lot of head aches and trouble. So basically I am looking to have an autosave as a different file name. If you are talented at scripting please help someone with little understanding of scripting. Thanks so much! - Xavier

repeat
tell application “Adobe Photoshop CS2”
activate
delay 10
set Button_pressed to display dialog “Do you need to save your work?” buttons {“No”, “Yes”} default button 2
if button returned of Button_pressed is “No” then
tell application “Adobe Photoshop CS2”
activate
delay 10
end tell
else
tell application “System Events”
tell process “Adobe Photoshop CS” to keystroke “s” using command down
end tell
end if
end tell
end repeat

Hi Rainmma

Let me know if this works for you.

repeat
	tell application "Adobe Photoshop CS"
		activate
		delay 3
		set Button_pressed to display dialog "Do you need to save your work?" buttons {"Cancel", "No", "Yes"} default button 2 --added cancel give you the option to kill script
		if button returned of Button_pressed is "No" then
			--continue 
		end if
		if button returned of Button_pressed is "Yes" then
			tell application "Adobe Photoshop CS"
				activate
				save current document
				set x to file path of current document
				tell application "Finder"
					if not (the folder "backup images" of desktop exists) then
						make new folder at desktop with properties {name:"backup images"}
					end if
					duplicate x to folder "backup images" of desktop with replacing
				end tell
			end tell
		end if
	end tell
end repeat

i think this is the only way to do it unless you want lots of files building up like image 1 then image 2 etc… etc…
so this just saves the file then copies it to another folder so you have a duplicate from your last save everytime you click yes in a separate folder
and it replaces everytime.
Someone else on this forum may have a better idea but i think this works.
feel free to adjust it to your own needs.

let me know how you get on

The script works pretty well. I got it to save on the desktop folder backup images. Where in the script though can I designate where I really want to save it other than the desktop. Like on my HD somewhere? The script said it timed out why does it time out? Is it because the photoshop file is taking to long to save because it is a big file and the repeat time is too short? Besides these minor issues the script so far is great, it is pretty genious! thanks, I really appreciate your help…

other problems I found

when you open a new file and save the script is not running for that image. why?

when I hit cancel I think it terminated the script? is the so?

I think the issue is with X as a variable.

this is the part of the script that it has trouble with

set x to file path of current document
tell application “Finder”
if not (the folder “backup images” of desktop exists) then
make new folder at desktop with properties {name:“backup images”}
end if
duplicate x to folder “backup images” of desktop with replacing

Sorry but this is not a scripting solution, more an old hack remembering stuff done in the old days.

When quark was very unstable and Mac’s would crash at the most at the most inappropiate time (usually within the last picture import of the last spread of a book !!!) the practice would to open the file and do a save as. (you could also set quark to save at certian intervals)Then simply hit comand -s after every major change… It took me years to get out of the habit.
I have hardly had a crash on my macs running OSX apart from a liquid cooled dual which would crash for no reason. This mac eventually died and the problem was the coolant leaked out and screwed the power supply. It also wrecked the processor.

HI Rainmma

If it takes longer than 2 minutes to save your image the script may time out cause the dialog will be waiting for input during that time.
should be able to get round that by using a with timeout statement!
if you want to save your image to the same place everytime then you can hardcode the file path into the script i just pointed it towards a folder on the desktop
for ease.
just point it towards another folder that you want!
you could also add a choose folder command so the script would prompt you for a place to save, (think this would not save you much time though)

When you open a new file you will need to start the script running again!

Yes! Pressing cancel will terminate the script!!

Not sure what you mean about the trouble with the x variable??

The only problem with this method of duplication to preserve a back-up copy of the opened file is human error (forgetting to run the script when opening a file) to me this is just as much user input as comm+D on file then comm+O What may be a better solution is a JavaScript this can be added to Photoshops Scripts Events Manager as an open file event. I haven’t looked too far into this just yet but think its Java only may be someone knows more about this. Its where I would be looking for a solution to this. Another solution to auto back-up would be to save file if modified to specific folder location. Here is a quick example I’ve knocked together it only looks at the current document though every 60 secs to see if its changed but you should be able to work this up into a better script.

on run
	set PS_CS to false
	tell application "System Events"
		if exists process "Adobe Photoshop CS2" then
			set PS_CS to true
			-- display dialog "Adobe Photoshop CS2 is active." giving up after 2
		else
			set PS_CS to false
			-- display dialog "Adobe Photoshop CS2 is inactive." giving up after 2
		end if
	end tell
	repeat while PS_CS is true
		tell application "Adobe Photoshop CS2"
			-- activate
			if exists current document then
				set docRef to the current document
				set docName to name of docRef
				if modified of docRef is true then
					tell application "Finder"
						if not (exists folder "backup images" of desktop) then
							set x to make new folder at desktop with properties ¬
								{name:"backup images"}
						else
							set x to ((path to desktop folder) & "backup images") as string as alias
						end if
					end tell
					set DupeFile to ((x as string) & docName) as string
					save docRef in file DupeFile
				end if
			end if
		end tell
		delay 60 -- Time in seconds to repeat
	end repeat
end run
--
on idle
	--
end idle