Making button and text boxes visible on a condition

how would i make it so that a button and a few text boxes are only visible if the application “Speakableitems” is running?

Greetings.

Took me a bit to figure this one out. :slight_smile: The code below worked for me with a few tests, so I assume it’ll work for you. I used a ‘will open’ event attached to the window displaying the button/text fields so they were set visible or not before the window is displayed.

Change the “MY_APPLICATION” part to the exact name of the process (app) you want to check if running or not.

The code also saves the variable currProcessesText as a comma-separated list of all of the currently running apps. A line of code also writes the list to a text field “textField” in the generic window. Anything with a “–< LIST >” after it is only used for making this list, and can be deleted if you don’t have a need for the list of app names.

on will open theObject
	set appFound to false

	set comma to "" --< LIST >
	set currProcessesText to "" --< LIST >

	tell application "Finder"
		set currProcesses to every process whose file type is "APPL"
	end tell
	
	repeat with x in currProcesses
		set tempProcess to name of x
		set currProcessesText to currProcessesText & comma & tempProcess --< LIST >
		set comma to "," --< LIST >
		if tempProcess is "MY_APPLICATION" then -- Change this part
			set appFound to true
		end if
	end repeat
	
	set contents of text field "textField" of window "theWindow" to currProcessesText --< LIST >

	-- Code below sets the visibility of the textboxes and button,
	-- depending on whether the app has been found (appFound = true)
	if appFound is true then
		set visible of button "Button" of window "theWindow" to true
		set visible of text field "TextField1" of window "theWindow" to true
		set visible of text field "TextField2" of window "theWindow" to true
	else
		set visible of button "Button" of window "theWindow" to false
		set visible of text field "TextField1" of window "theWindow" to false
		set visible of text field "TextField2" of window "theWindow" to false
	end if
end will open

Hope this works for you…

j