I'm trying to automate opening and saving a file in applescript. I can't seem to get consistent results with the save dialog though. Is it possible to change a save dialog to a specific folder in applescript?
Asked
Active
Viewed 1,821 times
1
-
Which program are you using to open it? – adayzdone Nov 16 '12 at 17:00
-
SketchUp... which doesn't have automator hooks :( – nothappybob Nov 16 '12 at 17:16
-
You can use AppleScript's ui scripting via system preferences to click menu items or perform keystrokes. – adayzdone Nov 16 '12 at 17:25
-
I have been. Unfortunately, there doesn't seem to be a way to consistently navigate to a folder. – nothappybob Nov 16 '12 at 17:37
2 Answers
2
This might help you navigate to a folder once the save dialog is raised:
set the clipboard to "/path/to/your/folder"
tell application "System Events" to tell process "SketchUp" -- I'm guessing on SketchUp name
keystroke "G" using {command down, shift down}
delay 1
keystroke "v" using {command down}
delay 1
keystroke return
delay 1
keystroke return
delay 1
end tell

adayzdone
- 11,120
- 2
- 20
- 37
-
Awesome! I figured out the solution on my own and came back to find that you had posted the same answer :) – nothappybob Nov 16 '12 at 18:55
0
You can do it and keep your clipboard intact, I think. If your save dialog is in TextEdit, if you last saved something to the desktop, for example, the following would change your destination back to Documents. It's easier just to use ⌘+D for that, of course, but you can use substitute pretty much whatever path you need. If you have a path with a folder having non-AppleScript allowable characters in the path (such as quotes), you can escape each with the backslash ("\") character.
tell application "TextEdit"
activate
try
tell application "System Events"
keystroke "g" using {shift down, command down}
do shell script "sleep 0.2"
keystroke "~/Documents"
do shell script "sleep 0.2"
keystroke return
end tell
end try
end tell