Hi, I’m new to these forums. I’m not too familiar with Apple Scripting or scripting in general, and I’m hoping someone here could help me out with a script (one that I think would be simple to do).
Basically I want to tell an application to hit a specific keystrokes every so often. Hopefully it’s generic enough that I could translate it to several other programs.
To be specific, I would like to tell Maya to save my scene (Apple + s) every 10 minutes or so.
Any help would be appreciated. Let me know if I could be any clearer.
on idle
activate application "Maya"
tell application "System Events"
tell process "Maya"
keystroke "s" using {command down}
end tell
end tell
return (10 * 60)
end idle
Thanks Bevos. I’ll try it out when I get home. Does this script run automatically every X minutes?
Part of the reason I want it to happen every so often is because I forget to save sometimes and when Maya crashes (due to my large scenes) I sometimes loose work. I just want to use it as a safety measure.
When you have a “stay open” applescript, then the value you return in the “on idle” handler determines the number of seconds the script waits. So in Bevos’s script the last stement, “return (10*60)” means execute the code every 600 seconds.
I opened the script, saved and hit Run, but it doesn’t appear to do anything. Is there anything special I need to do to activate the script? Also, how can I tell if it’s running?
At the bottom of the save dialog there’s a box “Stay Open”. You have to check it. You’ll know it’s running because it will show a script icon in the dock with the name you gave it. Quit it from the Dock.
Thanks! I got it to work. I didn’t see that option to save it as an app. This will help me a lot!
Curious, though not a huge deal, is it possible to have this script do what it does in the background? For example is I was editing photos in Photoshop, would it be possible to have the script perform a similar keystroke without bringing the Maya to the front?
When you use keystroke commands, the application has to be the front application. But maybe maya has a “save” applescript command. That’s a pretty standard command that most applications seem to have. If it does then you can have it do its thing in the background without making it the front application.
something like this might work…
on idle
tell application “Maya”
save document 1 – or save window 1 – or save document “document name” etc.
end tell
return (10 * 60)
end idle
When you use the word “activate”, that’s what brings it to the front. You can use the word “launch” instead if you need to open the application but not bring it to the front. But in your case it sounds like maya is already running, so you don’t even need either of these if you’re not using keystroke commands.
You likely want to save all open documents. Not just the frontmost with commands. Also untitled document are a problem. Maybe you save a copy, or make a backup. Fun thing about Applescript is 20% of work get 80% there and for the prefection 20% more you do 80% work. That what professionals are pay to do.
If only I had the dictionary. Maya says they got basic AppleScript support. Which should have save. With a link to there advanced MEL Scripting Language.
tell application "Adobe Photoshop CS2"
save every document
end tell
Just remeber the front most process and return to it when your script ends
For fun someone may want to write a script that works out every application (Appliscriptable and not) running and save every document.