Keystroke return not working - help!

Hi guys,

I’m having a few problems with Toast Titanium 10 scripting.

Generally everything is working fine (to a point of testing) but I can’t get the Keystroke Return to work when the main Burn Window appears.

This is the message from the events window.

tell application "Finder"
get keystroke "
"
--> error number -1728 from keystroke "
"
Result:
error "Finder got an error: Can't get keystroke \"
\"." number -1728 from keystroke "
"

I’m a total novice working through my first script (ongoing project), but until I can get this section to work, I’m pretty much stuck, so any help would be greatly appreciated.

Many thanks,
Steve

Suppose I open TextEdit. Then under the file menu I choose print. Now that I have the print sheet open I can get all of the ui elements of the print sheet like this…

tell application "TextEdit" to activate
delay 0.5
tell application "System Events"
	tell process "TextEdit"
		UI elements of sheet 1 of window 1
	end tell
end tell

So looking at the ui elements I can determine which one I need to do something. However, if I wanted to click the “Cancel” button on the sheet that’s simple because I know the ui element is a button and I know the title of the button is “Cancel”… so I could do this without even knowing all of the ui elements.

tell application "TextEdit" to activate
delay 0.5
tell application "System Events"
	tell process "TextEdit"
		set theButton to first button of sheet 1 of window 1 whose title is "Cancel"
		click theButton
	end tell
end tell

So you see it’s pretty simple to find ui elements and it’s even more simple to click buttons.

Am I reading wrongly ?

I understood that the OP wanted to get the info : “which key was depressed”, not “how may we issue a key stroke”.

Yvan KOENIG (VALLAURIS, France) jeudi 19 août 2010 12:53:41

Well that never occurred to me. I suppose you could be right. However, I don’t know how he would expect to do that with applescript. He could use a repeat loop checking if a sheet closed, or if the value of some text changed etc. but not which key was pressed. I guess well see what he meant when he responds.

Yvan, Hank,

Actually you’re both correct!
I’d very much like to understand how to figure out “which key was depressed” for troubleshooting or (I think you guys call it) Debugging a script! But for now I’d like to know which script would simply activate the Burn sequence in Toast.

My problem is that the script currently activates Toast, and opens a pre-saved project window with a couple of video clips already in it, and settings which have been saved. However, the script activates the “Record Disc” button (big red button on the bottom of the main Toast Project window), the next window appears but waits for the “Return” key to be pressed to start the burn. So no burn currently takes place.

Using a simple “Keystroke return” command, doesn’t work, so I’d like to get this to work first before moving forward to check the rest of the script.

Here’s my “attempt” at trying to get this to work (notes and all) . . . I know it’s not pretty and needs an awful lot of refining, but I’m enjoying the learning process - even though it’s taking me forever to get the hang of things.

set sourceFolder to "USB" as alias
set endtitles to alias ":Users:steve:Desktop:close.mpeg"
set thefile to alias ":Users:steve:Desktop:template.disc"

tell application "Finder" to set files_to_add_1 to every file of sourceFolder as alias list
tell application "Finder" to set files_to_add_2 to every file of endtitles as alias list

-- Note: Toast may also be run in server mode which according to the dictionary, allows for the progress bar to be seen but not the application - great! Just need to know how to implement it in the script!

tell application "Toast Titanium"
	set server mode to true
	-- Note: not sure if this works?? Seems to!
	open thefile
	set toast_project to current disc
	add to toast_project items files_to_add_1
	delay 3
	add to toast_project items files_to_add_2
	delay 3
	with timeout of 3600 seconds
		write toast_project with asynchronous completion without asking
		
		delay 5
		tell application "Finder" to keystroke return
		
--Note: Repeat command here?
		
		--  Note: Need checking in here - Toast is not writing -keystroke not working properly yet, & also I need to ensure that the DVD is written and ejected before the "DVD Disk Written Successfully" message appears.
		try
			tell application "Toast Titanium" to quit without saving -- could also be quit saving no
		end try
		--Note: end repeat?
	end timeout
end tell

activate
display dialog "DVD Disk Written Successfully"

Lots of other issues to sort out, but the burn situation first!

Thanks for your input . . . very much appreciated, and very helpful!

Cheers,
Steve

The Finder does not issue keystrokes, System Events does. System Events issues all keystrokes and button clicks as I showed above. You have to make sure the application you are targeting is frontmost before you tell system events to do that stuff. As such something like this will work. You still need something to check whether the DVD burn happened and when it finished. I don’t have Toast so I can’t help with that.

set sourceFolder to "USB" as alias
set endtitles to alias ":Users:steve:Desktop:close.mpeg"
set thefile to alias ":Users:steve:Desktop:template.disc"

tell application "Finder" to set files_to_add_1 to every file of sourceFolder as alias list
tell application "Finder" to set files_to_add_2 to every file of endtitles as alias list

-- Note: Toast may also be run in server mode which according to the dictionary, allows for the progress bar to be seen but not the application - great! Just need to know how to implement it in the script!

tell application "Toast Titanium"
	set server mode to true
	-- Note: not sure if this works?? Seems to!
	open thefile
	set toast_project to current disc
	add to toast_project items files_to_add_1
	delay 3
	add to toast_project items files_to_add_2
	delay 3
	write toast_project with asynchronous completion without asking
end tell

delay 4.5
tell application "Toast Titanium" to activate
delay 0.5
tell application "System Events"
	tell process "Toast Titanium"
		keystroke return
	end tell
end tell

-- add some checking here for when the dvd burn completes

tell application "Toast Titanium"
	try
		tell application "Toast Titanium" to quit without saving -- could also be quit saving no
	end try
end tell

tell me to activate
display dialog "DVD Disk Written Successfully"

Successful burn triggering found here:

http://macscripter.net/viewtopic.php?id=34138