My script worked perfectly in OSX 10.7.5 but dies in 10.10.1 I’m taking it apart a bit at a time and found this section that although is fine in Lion will not work in Yosemite. It’s part of a sub routine that places a value in MPEG Streamclip. Streamclip is not scriptable so i used system events to operate it. Something must be wrong with system events. Any ideas would be appreciated. The code below works in Lion and places the value in streamclip but does not in Yosemite. Any ideas would be appreciated.set startView to “39:39”
set startView to "39:39"
tell application "Finder"
set the clipboard to startView
end tell
tell application "MPEG Streamclip"
activate
end tell
tell application "System Events"
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1 of application process "MPEG Streamclip" of application "System Events"
keystroke "v" using command down
keystroke return
end tell
/applescript]
‘set the clipboard’ is a StandardAdditions command. You don’t need to tell the Finder to do it.
The first line inside the ‘tell application “System Events”’ statement mustn’t end with ’ of application “System Events”'. That’s already implied by it being inside the ‘tell’ statement.
You may need to insert a slight delay between that line and the next to allow whatever’s invoked by the menu item to appear on screen before the keystroke’s performed.
in addition to Nigel’s suggestions you might consider that the clipboard is not needed at all.
This is a version with a reliable delay before typing the time string
set startView to "39:39"
activate application "MPEG Streamclip"
tell application "System Events"
tell process "MPEG Streamclip"
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1
repeat until exists window "MPEG Streamclip"
delay 0.1
end repeat
keystroke startView
keystroke return
end tell
end tell
As the application is localized, I choose to write a code which is not attached to a given localization.
set startView to "3:19"
activate application "MPEG Streamclip"
delay 0.1
tell application "System Events" to tell process "MPEG Streamclip"
keystroke "g" using {command down}
repeat until exists window "MPEG Streamclip"
delay 0.1
end repeat
keystroke startView & return
end tell
At least on my machine, the delay inserted just after the activate instruction is required.
Without it the loop checking the availability of the window “MPEG Streamclip” never ends.
Yvan KOENIG (VALLAURIS, France) vendredi 16 janvier 2015 12:06:41
Delay helped a great deal. Yosemite must run faster than Lion. i now have a question on what does / display dialog/ do to a script. I have a number of functions where I inserted display dialog to check on a variable. With that statement in the code it functions as intended after i press the OK button. With that statement removed the section the code does not function as intended. My guess is that display dialog resets something or activates something but I’ve tried activating system events and the effected application to no avail. When I pull out the section of code and run it buy itself with out any display dialog it functions as intended but when placed back with all the other statements it won’t work without display dialog stoping the action,then it functions as intended.
Here is the script that plays in isolation
--on playSequence(startView)
set startView to ""
set startView to "34:35"
tell application "Finder"
set the clipboard to startView
end tell
activate application "MPEG Streamclip"
tell application "System Events"
tell process "MPEG Streamclip"
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1
keystroke startView
keystroke return
end tell
end tell
-end playSequence
Here it is embedded in the function
on playSequence(startView)
tell application "Finder"
set the clipboard to startView
end tell
display dialog "startView"
activate application "MPEG Streamclip"
tell application "System Events"
tell process "MPEG Streamclip"
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1
click menu item "Go to Time." of menu "Edit" of menu bar item "Edit" of menu bar 1
keystroke startView
keystroke return
end tell
end tell
if TimeFlag = "out" then
--activate application "MPEG Streamclip"
tell application "System Events"
tell process "MPEG Streamclip"
delay 0.2
keystroke "o"
keystroke return
end tell
end tell
end if
if TimeFlag = "in" then
tell application "System Events"
tell process "MPEG Streamclip"
delay 0.2
keystroke "i"
--keystroke return
end tell
end tell
end if
if playShow = "play" then
activate application "MPEG Streamclip"
tell application "System Events"
tell process "MPEG Streamclip"
delay 0.2
keystroke "l"
--keystroke return
end tell
end tell
end if
tell application "System Events"
activate
--display dialog "playShow"
end tell
end playSequence
The function sets an inpoint and outpoint in Streamclip and them plays the section of video.
If I knew what display dialog did to the operation I could figure out the rest of the massive code. Adding delay helped a number of other functions. The duplicate click lines are because for some reason the system picks up the previous set of numbers from the Go To Time box and just prints in the editor at the end of the program the number that should have gone in the Streamclips Go To Time box.
You folks have been a godsend in the original script which functions fine in Lion. Now if I can only get it going in Yosemite. Many thanks for your help.
Normally in AppleScript, the script waits for a signal that each command’s been carried out and completed before going on to the next. The ‘display dialog’ command doesn’t signal completion until the user clicks one of the buttons. The dialog then sends a signal back to the script which includes information about which button was clicked, etc. On receiving this, the script goes on to the next command.
With GUI scripting, the script’s controlling things indirectly via the proxy of the user interface. So if it tells System Events to, say, ‘keystroke “g” using {command down}’, it only waits for System Events to acknowledge that the keystroke’s been done. It doesn’t know if the process which receives the keystroke has finished carrying out the action it normally does in response to it. Thus the frequent need in GUI scripting for additional idling delays to allow things to happen before the script continues.
Sometimes there is an alternative to the delay.
Here is a modified version of the script which I posted yesterday :
set startView to "2:19"
activate application "MPEG Streamclip"
--delay 0.1
tell application "System Events" to tell process "MPEG Streamclip"
set frontmost to true # force the process to front
keystroke "g" using {command down}
repeat until exists window "MPEG Streamclip"
delay 0.1
end repeat
keystroke startView & return
end tell
The delay was inserted to allow the process to be frontmost.
I removed it and explicitly urge the process to be at front.
With this version I get the same behavior but the time used to bring to front is reduced to the minimum required duration.
After issuing the shortcut opening the “MPEG Streamclip” window the loop is here to give to the system the time required to display it.
My understanding is that Yosemite is basically faster than older systems but that the new tasks introduced to enhance security are eating processor cycles which in some cases slow processes which we were accustomed to see faster.
Under Mavericks, I’m quite sure that running the posted script would execute only once the test checking the existence of the window.
Here, under Yosemite, it’s executed twice.
Before leaving you, I wish to repeat that doing the job without using the clipboard is cleaner than using it.
Yvan KOENIG (VALLAURIS, France) samedi 17 janvier 2015 11:44:11
Success!
Nigel’s explanation of display dialog’s effects gave me the information I needed to get the routiens working again, Yvan and Stephan I even quit using the clipboard although I wish I knew why it works. I would also like to learn how “activate application” works. How does system events or streamclip become deactivated.
Why does this work without a tell-end tell
activate "System Events"
playSequence(startView)
stopSequence(startView) ------------------------------if adjust set cutOut to preview
if sequenceFlagOut = "Accept" then
set startView to cutOut
showMarker(startView)
setMarker()
end if
Why does this work with commands within the tell-end tell structure. Is system events deactivated after the end tell?
repeat
tell application "System Events"
activate
display dialog "What would you like to do" buttons {"Cancel", "Another Project"} default button 2
end tell
set choice to result
if choice = {button returned:"Another Project"} then exit repeat
if choice = {button returned:"Cancel"} then exit repeat
end repeat
I want to express my gratitude for all your help. I could not have cobbled together a 12 page script with out you basically writing sections of the code. When I started I think I had a 2 page script to read in numbers from Excel. Stephan rewrote it in 5 or 6 lines that worked perfectly.