keys pressed?

hey is there any way to script if keys pressed code? i am trying to have a mac mini start up to a slideshow without a keyboard or mouse(which i have done easy) now i need it so that if it breaks for what ever reason i can just press 3 buttons and it cuts the code. i’m trying to make my code idiot proof but the more i do that the harder it is for me to get in. any ideas? or ways of doing that?

You could try drop in ‘try/on error/end try’ lines to handle when it does break. I’m assuming this is on public display? And how does it break? Would a restart not sort out the issue?

no. i’m asking if there is a way to break it mid code by pressing down certain buttons. you know like on windows on start up you have to press control+alt+del. i want that but instead of bring up a login i want it to skip to the end of the code and exit it.

No by default applescript is single threaded thus procedural. It means it must complete and an event before it can receive another. However it is possible to make another process and control it. read my post here where I fully describe how you can do that

its not the issue of it working at all times and single threaded procedure, i can just make a second apple script to do that. its the fact i want a way out of the code via pressing keys or something other then command Q cus the way i made the code it doesn’t stop until the script is canceled.




set documentPath to (path to shared documents folder as text) & "slides:test.key"

repeat
   
   if "keynote" is not in "slideshow" then
       tell application "Keynote"
           open documentPath
           delay 2
           start slideshow 1
       end tell
   end if
       
end repeat


as far as i have seen testing the code command Q doesn’t stop it. that just stops keynote.

I’m not sure what you’re trying to do with this script because this line makes no sense to me…

if "keynote" is not in "slideshow" then

But in any case you can’t quit out of a repeat loop using cmd-q. Your best bet would be to just kill the running script from the command line. You could probably write a script that runs from a keyboard shortcut that would kill the running script.

But that’s not really a good solution. From what I’m guessing you may be doing in your script, you probably don’t want to be using a repeat loop anyway. You probably want to create a stay-open applescript application and use the on idle handler to repeatedly run some code. Using on idle is much more stable than a repeat loop for scripts that you want to leave running for any length of time. They have the additional advantage of you being able to quit them using command-q. Your code would look like the following in that scenario.

global documentPath

on run
	set documentPath to (path to shared documents folder as text) & "slides:test.key"
end run

on idle
	if "keynote" is not in "slideshow" then
		tell application "Keynote"
			open documentPath
			delay 2
			start slideshow 1
		end tell
	end if
	
	return 5 -- every 5 seconds the on idle handler is run again
end idle

Here’s an expanded solution from above if you need some other keyboard shortcut than command-q to quit the script… just use a second script to quit the first stay-open applescript application. For example create this and call it “testQuit”.

on run
	
end run

on idle
	-- do some stuff
	
	return 1
end idle

Now you create this second script. When you run this it will quit testQuit. This second script can be set to run from a keyboard shortcut using some program like butler… and thus you have your keyboard shortcut to quit out of the repeat loop (in this case its an on idle handler) of the first script.

tell application "testQuit" to quit

Is there just a way to see every button being pressed/held down at this moment?