Greetings,
I am very new to AppleScript and am trying to learn the ropes. I’ve been trying to write a script which will open up Camino for me, and then export my bookmarks in the Safari plist format. I’m having some problems, the first being setting the text field on the Save window, and the second actually clicking the “Export” button. Ideally, I want to save this script to my desktop as “Bookmarks.plist”.
If I am ever successful at getting this part fixed I am going move the exported file into my Safari folder, replacing the existing one - and if I wind up being able to do that it’d be nice to then sync dot mac… but baby steps, I just need to get this basic part working first.
Anyhow, here’s what I have. Again, I’m fresh meat to this turf, so any help that anyone can give me would be greatly appreciated. Thanks!
tell application "Camino"
activate
end tell
tell application "System Events"
tell process "Camino"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "Export Bookmarks."
end tell
end tell
end tell
tell window "Save"
tell sheet 1
set text field 1 of sheet 1 of window "Save" to "/Users/stan/Desktop/Bookmarks.plist"
tell pop up button 0
select "Safari"
end tell
click button "Export"
end tell
end tell
end tell
end tell
Stan Lemon
Model: iMac Duo Core 2 20"
Browser: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; chrome://navigator/locale/navigator.properties; rv:1.9a1) Gecko/20061021 Camino/1.2+
Operating System: Mac OS X (10.4)
If you want to save as plist, then you need to script the pop up button also. I haven’t succeeded in doing that yet.
This can get you started.
tell application "Camino"
activate
set the clipboard to "Bookmarks"
end tell
tell application "System Events"
tell process "Camino"
tell menu bar 1
tell menu "File"
click menu item "Export Bookmarks."
end tell
end tell
keystroke "v" with command down
keystroke return
(*
tell window "Save"
tell pop up button 1
UI elements
end tell
end tell
*)
end tell
end tell
set lib_folder to (path to "dlib" from user domain as string)
set bm_ref to ¬
(lib_folder & "Application Support:Camino:bookmarks.plist") as alias
tell application "Finder" to duplicate bm_ref to desktop
Kel,
Thanks, I ran the script with that change and got a bit closer… only problem is for some reason the keystroke return doesn’t seem to work right. Any ideas?
You might need to add a delay between the keystrokes.
delay 1 – adjust for whatever works
Anyway, if you don’t like using the clipboard, this works without using the paste method.
tell application "Camino"
activate
--set the clipboard to "Bookmarks"
end tell
tell application "System Events"
tell process "Camino"
tell menu bar 1
tell menu "File"
click menu item "Export Bookmarks."
end tell
end tell
--keystroke "v" with command down
--keystroke return
tell window "Save"
tell pop up button 1 -- pop up for switching to Safari
click
end tell
delay 2
tell group 2
tell group 1
tell text field 1
set value to "Bookmarks"
end tell
end tell
end tell
tell button "Export"
click
end tell
end tell
end tell
end tell
Remember that if things don’t work sometimes, adding delays makes it work.
I’m using Jaguar so things probably changed. Look in the dictionary for System Events. They have other commands like ‘pick’ and I think ‘press’. Apple Also added where you can set attributes. You might need that to select Safari from the popup menu. You can download ui element inspector to help you: