Check if an Amphetamine session is running

I thought this would be straightforward. Amphetamine uses ‘session is active’ to check if a session is, well, active. I want to use that and then do stuff based on whether it returns true/false. Here’s what I have:

tell application "Amphetamine"
	
	set SessionStatus to (session is active)
	
	if SessionStatus is "false" then
		log "Amphetamine is not running"
	end if
	
	if SessionStatus is "true" then
		log "Amphetamine is running"
	end if
	
end tell

And here’s what’s returned - you’ll notice that the logging isn’t happening. Seems like the script checks session activity and then nothing else.

tell application "Amphetamine"
	session is active
		--> false
end tell

What am I missing?

Hi @brijazz012. Welcome to MacScripter.

My first thought is that you may be looking at Script Editor’s “Result” pane. If you select “Show Log” in the “View” menu and then select any of the tabs in the lower pane other than “Result”, you should be able to see the log results. Alternatively, you could try “Log History” in the “Window” menu.

I do have “Show Log” enabled already, and am looking in the “Replies” pane. I even tried to get the script to read me the result out loud by replacing

log "Amphetamine is not running"

with

say "Amphetamine is not running"

…but still nothing.

Ah! I’ve just noticed that your script has “true” and “false” in quotes. Try removing the quotes. The (session is active) result’s a boolean, not text.

tell application "Amphetamine"
	
	set SessionStatus to (session is active)
	
	if SessionStatus is false then
		log "Amphetamine is not running"
	end if
	
	if SessionStatus is true then
		log "Amphetamine is running"
	end if
	
end tell

Or:

tell application "Amphetamine"
	
	set SessionStatus to (session is active)
	
	if (SessionStatus) then
		log "Amphetamine is running"
	else
		log "Amphetamine is not running"
	end if
		
end tell

Ah, dropping the quotes did the trick. Thanks!

Nigel’s second script is even cleaner