• 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: strange behavior setting window index to 1 in Safari
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: strange behavior setting window index to 1 in Safari


  • Subject: Re: strange behavior setting window index to 1 in Safari
  • From: Yvan KOENIG <email@hidden>
  • Date: Sat, 04 Jun 2016 21:31:51 +0200

Maybe there is a neater scheme but here is a piece of code which I use to solve this kind of problem.

set mt to 9
set theApp to "Safari"
tell application "Safari"
# Get the full name of the wanted window
set wanted to name of window 2
end tell


tell application "System Events" to tell process theApp
set frontmost to true
tell menu bar 1 to tell menu bar item mt to tell menu 1
# Build a list of items of menu Windows
set menuItems to name of every menu item
end tell
end tell

set windowNames to {}
repeat with aName in reverse of menuItems
if class of aName is not text then exit repeat
# Build a list of menu items pointing a window
set end of windowNames to (aName as text)
end repeat
-- windowNames

repeat with theWindow in windowNames
if theWindow contains "…" then
set maybe to my decoupe(theWindow, "…")
if wanted starts with maybe's item 1 and wanted ends with maybe's item -1 then
set theWindow to maybe's item 1 & "…" & maybe's item -1
exit repeat
else
# The menu item doesn't contain "…" so compare to window name
if theWindow = wanted then exit repeat
end if
end if
end repeat

tell application "System Events" to tell process theApp
set frontmost to true
# Bring the selected window to front
tell menu bar 1 to tell menu bar item mt to tell menu 1 to click menu item (theWindow as text)
end tell

#=====

on decoupe(t, d)
local oTIDs, l
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set l to text items of t
set AppleScript's text item delimiters to oTIDs
return l
end decoupe

#=====


Yvan KOENIG running El Capitan 10.11.5 in French (VALLAURIS, France) samedi 4 juin 2016 21:30:54




 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >strange behavior setting window index to 1 in Safari (From: Mitchell L Model <email@hidden>)

  • Prev by Date: strange behavior setting window index to 1 in Safari
  • Next by Date: Re: strange behavior setting window index to 1 in Safari
  • Previous by thread: strange behavior setting window index to 1 in Safari
  • Next by thread: Re: strange behavior setting window index to 1 in Safari
  • Index(es):
    • Date
    • Thread