stay-open display dialog

Hello,

Is it possible to create a display dialog which stays open? I am working on a script which searches PROs (i.e. performing rights organizations for music). The script does what it is supposed to do, but I received feedback from a friend who suggested that it would be more user-friendly if the search field remained open, so you could reuse it without having to reopen the app for every search. I know there is a “stay-open” option, but I don’t know of a stay-open display dialog, or if that is even the best idea. Does anyone know of a solution without learning Xcode?

Any advice would be much appreciated :slight_smile:



to ascapInput(theclass, num, theValue)
	
	tell application "Google Chrome"
		tell tab 1 of front window
			execute javascript "document.getElementsByClassName('" & theclass & "')[" & num & "].value ='" & theValue & "';"
		end tell
	end tell
	
end ascapInput

to bmiInput(theclass, num, theValue)
	
	tell application "Google Chrome"
		tell tab 2 of front window
			execute javascript "document.getElementsByClassName('" & theclass & "')[" & num & "].value ='" & theValue & "';"
		end tell
	end tell
	
end bmiInput

to ascapClick(theID)
	
	tell application "Google Chrome"
		tell tab 1 of front window
			execute javascript "document.getElementById('" & theID & "').click();"
		end tell
	end tell
	
end ascapClick

to bmiClick(theID)
	
	tell application "Google Chrome"
		tell tab 2 of front window
			execute javascript "document.getElementById('" & theID & "').click();"
		end tell
	end tell
	
end bmiClick

on run
	set searchBy to display dialog "Search by:" buttons {"Title", "Artist", "Writer"} with title "ProSearch" with icon 1 ¬
		default button "Title" giving up after 10
	
	if button returned of searchBy is "Title" then
		
		set titleQuestion to display dialog "Enter the title:" default answer "" with title "ProSearch" with icon 1
		set titleAnswer to text returned of titleQuestion as string
		
		tell application "Google Chrome"
			activate
			make new window
			make new tab in front window
			set URL of tab 1 of front window to "https://www.ascap.com/repertory"
			set URL of tab 2 of front window to "https://repertoire.bmi.com/StartPage.aspx"
			repeat until (loading of tab 1 of front window is false and loading of tab 2 of front window is false)
			end repeat
		end tell
		
		ascapInput("searchValue searchField", 0, titleAnswer)
		
		bmiInput("form-control form-inline main-search", 0, titleAnswer)
		
		ascapClick("startSearch")
		
		bmiClick("searchControl_btnSubmit")
		
	else if button returned of searchBy is "Artist" then
		
		set artistQuestion to display dialog "Enter the artist:" default answer "" with title "ProSearch" with icon 1
		set artistAnswer to text returned of artistQuestion as string
		
		tell application "Google Chrome"
			activate
			make new window
			make new tab in front window
			set URL of tab 1 of front window to "https://www.ascap.com/repertory"
			set URL of tab 2 of front window to "https://repertoire.bmi.com/StartPage.aspx"
			repeat until (loading of tab 1 of front window is false and loading of tab 2 of front window is false)
			end repeat
			tell tab 2 of front window
				execute javascript "document.getElementsByTagName('option')[3].value='artist';"
			end tell
		end tell
		
		ascapClick("performer")
		
		ascapInput("searchValue searchField", 0, artistAnswer)
		
		bmiInput("form-control form-inline main-search", 0, artistAnswer)
		
		ascapClick("startSearch")
		
		bmiClick("searchControl_btnSubmit")
		
	else if button returned of searchBy is "Writer" then
		
		set writerQuestion to display dialog "Enter the writer:" default answer "" with title "ProSearch" with icon 1
		set writerAnswer to text returned of writerQuestion as string
		
		tell application "Google Chrome"
			activate
			make new window
			make new tab in front window
			set URL of tab 1 of front window to "https://www.ascap.com/repertory"
			set URL of tab 2 of front window to "https://repertoire.bmi.com/StartPage.aspx"
			repeat until (loading of tab 1 of front window is false and loading of tab 2 of front window is false)
			end repeat
			tell tab 2 of front window
				execute javascript "document.getElementsByTagName('option')[3].value='writer';"
			end tell
		end tell
		
		ascapClick("writer")
		
		ascapInput("searchValue searchField", 0, writerAnswer)
		
		bmiInput("form-control form-inline main-search", 0, writerAnswer)
		
		ascapClick("startSearch")
		
		bmiClick("searchControl_btnSubmit")
		
	end if
	
end run


Stay-open not, but to do it be always returned - yes (and this is what your users need at the end point). I edited your script to do this, and to remove the repeated code parts.

Standard Additions have only modal display dialog. To do something better than the provided here code, you need some custom not modal display dialog. You can create one not modal display dialog using AsObjC.


repeat
	tell application "Google Chrome"
		activate
		set theRequest to button returned of (display dialog "Search by:" buttons {"Title", "Artist", "Writer"} with title "ProSearch" with icon 1 ¬
			default button "Title" giving up after 100)
	end tell
	
	if theRequest is "Title" then -- TIP: this if block no need if you name the buttons above lowercase
		set theRequest to "title"
	else if theRequest is "Artist" then
		set theRequest to "artist"
	else
		set theRequest to "writer"
	end if
	
	tell application "Google Chrome"
		set theChoice to text returned of (display dialog "Enter the " & theRequest default answer "" with title "ProSearch" with icon 1)
		
		make new window
		tell front window
			make new tab
			set URL of tab 1 to "https://www.ascap.com/repertory"
			set URL of tab 2 to "https://repertoire.bmi.com/StartPage.aspx"
			repeat until (loading of tab 1 is false and loading of tab 2 is false)
				delay 0.1
			end repeat
			tell tab 2 to execute javascript "document.getElementsByTagName('option')[3].value='" & theRequest & "';"
			if theRequest is "writer" then my ascapClick("writer")
			if theRequest is "artist" then my ascapClick("performer")
		end tell
	end tell
	
	my ascapInput("searchValue searchField", 0, theChoice)
	my bmiInput("form-control form-inline main-search", 0, theChoice)
	my ascapClick("startSearch")
	my bmiClick("searchControl_btnSubmit")
end repeat

----------------------------- Not RUN handlers ---------------------------------------------------------------------

to ascapInput(theclass, num, theValue)
	tell application "Google Chrome" to tell tab 1 of front window
		execute javascript "document.getElementsByClassName('" & "searchValue searchField[0].value ='" & theValue & "';"
	end tell
end ascapInput

to bmiInput(theclass, num, theValue)
	tell application "Google Chrome" to tell tab 2 of front window
		execute javascript "document.getElementsByClassName('" & theclass & "')[" & num & "].value ='" & theValue & "';"
	end tell
end bmiInput

to ascapClick(theID)
	tell application "Google Chrome" to tell tab 1 of front window
		execute javascript "document.getElementById('" & theID & "').click();"
	end tell
end ascapClick

to bmiClick(theID)
	tell application "Google Chrome" to tell tab 2 of front window
		execute javascript "document.getElementById('" & theID & "').click();"
	end tell
end bmiClick

NOTE: The easiest way to exit the endless loop is with the “Cancel” button of the second display dialog.

Should be:

set theRequest to button returned of (display dialog…)

The return value of display dialog is always a record.

I fixed this typo, but as I see the script something doesn’t correctly yet. Doesn’t change the title in the tab 2: Songwriters/Composers or Artist or Title sometimes.

Thank you for the replies! It seems to be getting closer, but the edited script seems to get stuck after the initial search and has to be force quit. I’ll study your changes and try to make it work on my computer. Thank you again!

Use choose from list dialog instead of first display dialog. This way you can 1) put more than 3 criteria, 2) use its button “Cancel” to quit:


repeat
	tell application "Google Chrome"
		activate
		set theRequest to choose from list {"title", "artist", "writer"} with title "ProSearch by:"
		if theRequest is false then return
		set theChoice to text returned of (display dialog "Enter the " & theRequest default answer "" with title "ProSearch" with icon 1)
		make new window
		tell front window
			make new tab
			set URL of tab 1 to "https://www.ascap.com/repertory"
			set URL of tab 2 to "https://repertoire.bmi.com/StartPage.aspx"
			repeat until (loading of tab 1 is false and loading of tab 2 is false)
				delay 0.1
			end repeat
			tell tab 2 to execute javascript "document.getElementsByTagName('option')[3].value='" & (theRequest as text) & "';"
			delay 0.1
			if theRequest is {"writer"} then my ascapClick("writer")
			if theRequest is {"artist"} then my ascapClick("performer")
		end tell
	end tell
	my ascapInput("searchValue searchField", 0, theChoice)
	my bmiInput("form-control form-inline main-search", 0, theChoice)
	my ascapClick("startSearch")
	my bmiClick("searchControl_btnSubmit")
end repeat

----------------------------- Not RUN handlers ---------------------------------------------------------------------
to ascapInput(theclass, num, theValue)
	tell application "Google Chrome" to tell tab 1 of front window to execute javascript "document.getElementsByClassName('" & "searchValue searchField[0].value ='" & theValue & "';"
end ascapInput

to bmiInput(theclass, num, theValue)
	tell application "Google Chrome" to tell tab 2 of front window to execute javascript "document.getElementsByClassName('" & theclass & "')[" & num & "].value ='" & theValue & "';"
end bmiInput

to ascapClick(theID)
	tell application "Google Chrome" to tell tab 1 of front window to execute javascript "document.getElementById('" & theID & "').click();"
end ascapClick

to bmiClick(theID)
	tell application "Google Chrome" to tell tab 2 of front window to execute javascript "document.getElementById('" & theID & "').click();"
end bmiClick