.app form of an AppleScript created with Script Debugger only works in Script Debugger

I created an AppleScript program that searches for any Safari tab URL title containing a user-specified string, and it works fine when I run from Script Debugger, but saving this as an “.app” type application from Script Debugger it just hangs when I double-click the icon on the desktop.

Any ideas what might be causing it to hang but yet work fine when run in Script Debugger?

Here is the AppleScript if you would like to make any suggestions:

=================start of applescript program=========================

set question to display dialog ("Find Safari tab:") default answer ""
set searchpat to text returned of question

with timeout of 1200 seconds
	
	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
				if (tablist is not missing value) 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 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
	
end timeout

=================end of applescript program=========================

I just do a “Save as” an “Application (Apple)” in the Desktop folder of my user account, using Script Debugger 7.0.10 on macOS High Sierra.

Thanks…

-bob

Works perfectly here under High Sierra, after one request for permission.

Works when double-clicking the icon on the desktop or works from within Script Debugger?

Works when double-clicking the app on the desktop - what you asked about and said didn’t work on your system.

32%20PM

And it finds the url that I type in to the field and changes the focus in Safari to that tab.

Did you save it with debugging on?

1 Like

Yipppppeeeeee!!!

That must have been it – saved again after turning off debugging and it now works fine.

Thanks so much, it’s been driving me nuts trying to figure why it works in Script Debugger and not when saved. Now that I look closely at the icons on the Desktop the one that works does not show the little ladybug in the icon that the one saved with Debug turned on shows but does not work. Is that how you know for sure if debugging is turned on or off (ie the ladybug is part of the icon)?

Thanks very much!!!

-bob

ps – what is different about what is saved when debugging is turned on or off?

By the way, anyone is welcome to use this AppleScript to help find particular Safari tabs. I have a bad habit of having lots of Safari windows and tabs and it really helps find the one I know is there somewhere but Safari isn’t very helpful in finding the exact one I’m looking for. I adapted another script I found somewhere (but don’t recall exactly), so can’t take all the credit for this – so thanks to whoever wrote the AppleScript code that I started with!!!

-bob

Yes.

It’s actually using a different engine than standard AppleScript.