• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: scripting safari and menu items
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scripting safari and menu items


  • Subject: Re: scripting safari and menu items
  • From: kai <email@hidden>
  • Date: Sun, 13 Feb 2005 18:07:19 +0000


On Sun, 13 Feb 2005 13:40:55 +0100, Christian Vinaa wrote:

i seem to be lost in a never maze of problems

first i wanted script safari
basically just save the front document

tell application "Safari"
        activate
        open location " http://webcam.aet.ch/traffico/airolo_n.jpg"; ;
save  blabla
end tell

For some reason, Christian, I couldn't access the above url when I tried earlier (probably just a temporary glitch). For the examples below, I've therefore used an alternative - which you can obviously modify according to your needs.


that didnt work

Try something like this, instead:

-----------------------------------

set tgtURL to "http://www.apple.com/"; (*modify as required*)
set fileName to "Safari Test" (*modify as required*)
set fldrPath to (path to desktop)'s POSIX path (*modify as required*)

tell application "Safari"
open location tgtURL
repeat while (count documents) is less than 1 or (count (document 1's URL)) is less than 1 -- wait for url to load
end repeat
save document 1 in fldrPath & fileName & ".html"
end tell


-----------------------------------

so i tried   menu and menu items

--tell application "System Events"
        --      tell process "Safari"
        --select menu item 7 of menu 3 of menu bar 1
        --      end tell
        --end tell

but that didnt work  either
( and it was a pain to get the correct  item numbers ! )

I suspect that you may have specified a menu separator, rather than a menu item. In addition, it often helps to push the target application to the front for GUI scripting. I've used the pick command here, referring to menu names rather than numbers (which should make everything a bit easier to recognise):


-----------------------------------

tell application "System Events" to tell process "Safari"
	set frontmost to true
	pick menu item "Save As…" of menu "File" of menu bar 1
end tell

-----------------------------------

i seem to recall from OS 9 that you could get list af menu's pretty easy but how ?

I don't particularly recall that in OS 9, but it should certainly be possible in OS X, using System Events. Try running the following script. It should create a sample GUI menu script, for a chosen (visible) process, in a new Script Editor window:


-----------------------------------

--====================
-- GUI AutoMenu Script
--====================

to chooseItem(i, l)
	set c to choose from list l with prompt "Choose a " & i & ":"
	if c is false then error number -128
	c's item 1
end chooseItem

tell application "System Events"
set p to my chooseItem("process", name of processes whose visible is true)
tell process p to tell menu bar 1
tell menus to set m to my chooseItem(p & " menu", name)
tell menu m to tell menu items to set i to my chooseItem(p & " menu item", name)
end tell
end tell


tell application "Script Editor" to make new document at end with properties {contents:"tell application \"" & p & "\" to activate" & return & return & "tell application \"System Events\"" & return & "repeat until \"" & p & "\" is in name of processes" & return & "end repeat" & return & "tell process \"" & p & "\" to pick menu item \"" & i & "\" of menu \"" & m & "\" of menu bar 1" & return & "end tell" & return}

-----------------------------------

Finally, remember that you don't *have* to use a browser like Safari to save a web page. Here's an alternative method, using URL Access Scripting, which should download the relevant data direct:

-----------------------------------

set tgtURL to "http://www.apple.com/"; (*modify as required*)
set fileName to "Safari Test" (*modify as required*)
set fldrPath to path to desktop as Unicode text (*modify as required*)

tell application "URL Access Scripting" to download tgtURL to fldrPath & fileName & ".html" replacing yes

-----------------------------------

---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: scripting safari and menu items
  • Next by Date: get text from file after open for access
  • Previous by thread: Re: scripting script editor
  • Next by thread: get text from file after open for access
  • Index(es):
    • Date
    • Thread