Newbe needs help with a macro

Hello, I’m new to Keyboard Maestro and while I’m usually pretty tech savvy, this program is stumping me. I’m a video editor with lots and lots and lots of QuickTime movies that need to be saved as “auto play”.

I just can’t figure out how to set up this macro. I’m hopeful someone can provide me info (or even, if I dare hope, the acutal macro instructions!). I’m on late 2013 MacPro on OS 10.10.5 with a full-size keyboard with numeric keypad.

Here’s what needs to happen, step-by-step, once I’ve opened a movie in QuickTime Player 7 (Yes QT 7, NOT the newer QT Player 10.4):

  1. Press an assigned macro key (say, F6)
  2. Next, “Command J” has to be typed which opens the “Properties for” tab
  3. Next, the macro needs to select the “Presentation” tab
  4. Next, the “Automatically play movie when opened” needs to be check marked in the empty box
  5. Next, “Shift Command S” needs to be pressed so the “save as” tab appears. The filename would be something like “originalfilename*.mov”
  6. Next, the right arrow needs to be pressed so the cursor moves to the end of the filename but before the .mov extension (this is the default cursor placemet)
  7. Next, delete needs to be pressed one time, so the * at the end of the filename gets removed so the new file is simply “originalfilename.mov” (note, no asterisk)
  8. Next, the macro needs to select “Save”. (“Save as a self-contained movie” is the default selection in QuickTime 7.)

Voila! The new auto play movie will save right next to the original movie in the same folder. Hitting the same macro on each movie that needs to be set to auto play will save me oodles of time (8 steps each time!)

Can anyone help me with this probably simple macro?

Thanks big-time in advance,

Reed

Hi Reed,

There's almost certainly a better way to do this, most likely with AppleScript, but this should get you started. Please note that you may need to adjust the mouse click coordinates to ensure that the "Presentation" tab and checkbox clicking actions work as intended, and feel free to ask if you have any follow-up questions.

Save Video as Auto-Play.kmmacros (7.9 KB)

Fantasitc! I’m going to try this a bit later today. Thanks so much!

1 Like

After a few small tweaks, this macro worked great. Thanks again for your help! Really appreciate it!

1 Like

For those interested in an AppleScript version.
I tend to prefer the repeat loops rather than the delays because it is less machine or load dependent.

Place this in a Keyboard Maestro macro as an Execute AppleScript action and assign the triggering shortcut, or assign the keyboard shortcut through any of the other means, including the System Preferences keyboard route.

tell application "System Events"
tell process “QuickTime Player 7”

	set frontmost to true
	repeat until exists menu bar item "QuickTime Player 7" of menu bar 1
	end repeat
	set movieWindow to title of window 1
	
	keystroke "j" using command down -- Show Movie Properties command
	repeat until exists (windows whose title contains "Properties for") -- Wait for the Properties window to appear
	end repeat
	set propertiesWindow to first item of (windows whose title contains "Properties")
	tell propertiesWindow
		click radio button 4 of tab group 1 -- Presentation tab
		click checkbox "Automatically play movie when opened" of tab group 1
		click button 1 -- Close button
	end tell
	repeat until not (exists propertiesWindow) -- Wait for the Properties window to disappear
	end repeat
	
	tell window movieWindow
		keystroke "s" using {command down, shift down} -- Save as version of save
		repeat until exists sheet 1 -- Wait for the Save sheet to appear
		end repeat
		key code 124 -- Right arrow key
		key code 51 -- Delete key
		click button "Save" of sheet 1
		repeat until not (exists sheet 1) -- Wait for the Save sheet to disappear
		end repeat
	end tell
	
end tell

end tell

Hey Reed,

It’s always a good ides to see if the app you’re working with is scriptable.

QuickTime Player 7 is more scriptable than QuickTime Player 10.x, so you’re in luck.

Run this AppleScript from an Execute an AppleScript action:

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/04/29 19:47
# dMod: 2017/04/29 19:47 
# Appl: QuickTime Player 7
# Task: Turn ON auto-play in the front document and save as a new document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @QuickTime_Player_7, @Activate, @Auto-play, @Front, @Document, @Save, @New, @Document
------------------------------------------------------------------------------

tell application "QuickTime Player 7"
   
   tell front document
      
      if auto play = false then
         set auto play to true
      end if
      
      # Create new save path by adding "-ap" to the file name:
      set AppleScript's text item delimiters to "."
      set movieFile to text items of (original file as text)
      tell movieFile to set its item -2 to (get its item -2) & "-ap"
      set newSavePath to movieFile as text
      
      save self contained in newSavePath
      close
      
   end tell
   
end tell

------------------------------------------------------------------------------

It’s a much more organic process than using a Keyboard Maestro Macro or UI-Scripting with System Events.

-Chris

Hey @djgregg,

While it IS good practice to use concrete conditions for flow-control in scripts, it’s poor practice to use empty loops as pause-until-constructs. They unnecessarily overuse the processor.

It’s a good idea to employ a pause statement – even if it’s a small one like 0.25 seconds (or even less).

It’s also a good idea to enforce an exit condition or timeout to prevent the possibility of an endless loop:

------------------------------------------------------------------------------
set pauseTimeInSeconds to "0.25"
set timeoutDuration to 5 -- seconds
set timeoutValue to timeoutDuration div pauseTimeInSeconds
set timeoutCounter to 0

set pieInTheSky to false

repeat while pieInTheSky ≠ "TANSTAAFL"
   set timeoutCounter to timeoutCounter + 1
   
   delay pauseTimeInSeconds
   
   # Enforced Exit Condition
   if timeoutCounter > timeoutValue then error "Problem in “Repeat 1”!"
   
end repeat
------------------------------------------------------------------------------

** This could be written with more brevity of course.

Under some circumstances you can use AppleScript’s own with timeout blocks.

------------------------------------------------------------------------------
with timeout of 5 seconds
   # your statements
end timeout
------------------------------------------------------------------------------

But these don’t always work as you’d expect and should always be tested.

-Chris

1 Like

Hi Chris,

I appreciate your comments, and also the recommendation to use the native AppleScript scripting dictionaries over the GUI scripting.

My previous answer was trying to provide a direct equivalent to the macro so the forum could see how they are similar and differ. Unfortunately, I decided to go the route of the repeat vs the delay statements for that illustration.

Now for a response to your comments.

I probably should have added more of an explanation as why I prefer the repeat loops vs the delays.

Open-ended repeat loops

You are correct, in that the open-ended repeat loops is considered to be bad programming practice. The repeat loop can still be used with a design like the following to provide the exit provision.

set finalTimeSeconds to (seconds of (current date)) + killTime
repeat until exists window 1 – Wait for the Properties window to appear
if seconds of (current date) ≥ finalTimeSeconds then return
end repeat

Undoubtedly, there are more effective/efficient methods for providing that exit provision than indicated above. Suggestions?

Unnecessary overuse of the processor

In the case where the user is going to be triggering, and personally using the macro/script, I prefer to include more than hardware usage in the criteria for script design. I believe the user experience should also be included, does the response seem natural, and fluid. In these types of instances that may even overshadow the efficient usage of hardware criteria. Use of the delay statement, often results in a slower and choppier response.

In other cases, such as overnight or batch processing, maybe the user experience can be totally ignored. These scenarios may be more effectively programmed using the delay.

Other advantages to using the repeat loop method

The repeat loop method:

  • automatically uses just the right amount of time for the GUI to respond before the next AppleScript statement is executed; the delay method requires the user/scripter to test various delay times to fully optimize that timing, and I believe there is a limit to how small a floating point setting can be effectively used by the AppleScript delay statement.
  • optimization for different computers, and their loading at the time of the script execution, is built into the repeat method; the delay method may require further tinkering with the times or the use of a single high number to cover off the differences.

Hey @djgregg,

I provided one.

There's nothing wrong with using a repeat in this way, as long as you provide a concrete exit condition (as I already mentioned). I've done it many times.

There are situations where you can cheat and not provide a backup exit strategy (and I have), but that's not good practice.

Since someone will inevitably use your code, I though it a good idea to discuss good practices at least a bit.

Sure, but you can generally achieve nice, smooth interactions while employing pauses of ± 1/10 of a second. The time can be adjusted for the job – sometimes 1 or more seconds is appropriate — sometimes no pause is really necessary.

The point is to carefully consider the needs of the individual task.

One final bit of good-practice advice:

It's a good idea to avoid using keypresses in System Events whenever possible by directly selecting menu items (etcetera), since keypresses are especially easy for the user to interfere with.

-Chris