Solved

Applescript to perform action

Posted on 2014-02-08
2
371 Views
Last Modified: 2014-02-12
Hello Experts,

I am new to Applescript, and to be honest - i don't know anything about it, other than it's code that automates actions.  I know where to paste the code into, but that's about it.

I would like a code, that performs the following steps.

1.)  Script looks at ALL open windows.
2.)  Script brings all windows to the front, that have a specific word in the title.

Btw, the windows I mainly want it looking at are safari windows.

I'm hoping that simple enough to code.
0
Comment
Question by:Geekamo
2 Comments
 
LVL 1

Author Comment

by:Geekamo
ID: 39844010
And to add...

I could have maybe 15 safari windows open, some may just be popups - some are the main window with tabs.

So I only want this to prefer the action on safari windows that match a specific title.

I am *NOT* looking for 'safari' to be brought to the front, only the safari windows that match.

I hope that made sense.

Thank you in advance for your help.
0
 
LVL 39

Accepted Solution

by:
Eoin OSullivan earned 500 total points
ID: 39845161
This AppleScript finds matching Safari tabs and windows and if only one is found brings it to the front ... if more than one match is found it presents a dialog for you to select
set question to display dialog ("Find Safari tab:") default answer ""
set searchpat to text returned of question

tell application "Safari"
	set winlist to every window
	set winmatchlist to {}
	set tabmatchlist to {}
	set tabnamematchlist to {}
	repeat with win in winlist
		set ok to true
		try
			set tablist to every tab of win
		on error errmsg
			--display dialog name of win as string
			set ok to false
		end try
		if ok then
			repeat with t in tablist
				if searchpat is in (name of t as string) then
					set end of winmatchlist to win
					set end of tabmatchlist to t
					set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ".  " & (name of t as string)
					--display dialog name of t as string
				else if searchpat is in (URL of t as string) then
					set end of winmatchlist to win
					set end of tabmatchlist to t
					set end of tabnamematchlist to (id of win as string) & "." & (index of t as string) & ".  " & (name of t as string)
					--display dialog name of t as string
				end if
			end repeat
		end if
	end repeat
	if (count of tabmatchlist) = 1 then
		--display dialog "one!"
		set w to item 1 of winmatchlist
		set t to item 1 of tabmatchlist
		set current tab of w to t
		set index of w to 1
	else if (count of tabmatchlist) = 0 then
		display dialog "No matches"
	else
		set whichtab to choose from list of tabnamematchlist with prompt "The following tabs match, please select one:"
		set AppleScript's text item delimiters to "."
		if whichtab is not equal to false then
			set tmp to text items of (whichtab as string)
			set w to (item 1 of tmp) as integer
			set t to (item 2 of tmp) as integer
			set current tab of window id w to tab t of window id w
			set index of window id w to 1
		end if
	end if
end tell

Open in new window


copied from this page
http://hea-www.harvard.edu/~fine/OSX/safari-tabs.html

Unfortunately you cannot cycle through ALL application windows in this manner

There are scripts to get a list of open windows in all applications
tell application "System Events"
   set allWindows to name of window of processes whose visible is true
end tell
set windowList to {}
repeat with i in allWindows
   repeat with j in i
       if contents of j is not missing value then set end of windowList to contents of j
   end repeat
end repeat

Open in new window


You'll have to do some work to create a combination of the two scripts as I'm not in a position to write it for you.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface   In the first 100 days of the Macintosh release in January 1984, Apple sold 72,000 of the computers. Relatively cheap, easy-to-use personal computer with a graphical operating system. I've never seen this model. I did see this one:   …
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question