quicktime mute all files droplet - macos

Want an applescript droplet that opens files in QuickTime and mutes them all. The script only mutes the front most opened file.
on open the_Droppings
tell application "QuickTime Player 7" to activate
tell application "QuickTime Player 7" to open the_Droppings
tell application "System Events" to tell process "QuickTime Player 7"
keystroke (ASCII character 31) using {command down, option down}
end tell
end open

You need to tell each window open in Quicktime in turn to perform the action. An action has to have a specific target in Applescript; they way you have it written now, you are tell the Quicktime application, not a window in Quicktime.
Untested:
on open the_Droppings
tell application "QuickTime Player 7" to activate
tell application "QuickTime Player 7"
open the_Droppings
set documentCount to (count documents)
end tell
repeat with thisDocument from 1 to documentCount
tell application "System Events"
tell process "QuickTime Player 7"
tell document thisDocument
keystroke (ASCII character 31) using {command down, option down}
end tell
end tell
end tell
end repeat
end open
But I believe there is also a preference to not have movies auto-play upon opening as well.

Here is the way I got it to work.
on open the_Droppings
activate application "QuickTime Player 7"
repeat with oneDrop in the_Droppings
tell application "QuickTime Player 7"
open oneDrop
set sound volume of document 1 to 0
end tell
end repeat
end open

Related

Quicktime Player recording with Applescript broken on Mavericks?

I have this simple code:
tell application "QuickTime Player"
activate
new screen recording
document "Screen Recording" start
delay 10
document "Screen Recording" stop
end tell
This records a 10-second movie on my 10.8 machine with no problem.
But on 10.9 mac-mini, QT hangs at the stop action above.
It hangs at the window with message "Finishing Recording".
I have to force quit it and still same thing. If I do these steps manually, they work. But with AppleScript or even same steps with Automator have same issue.
I upgraded to 10.9.2, but still same issue.
Is this a known bug? Any suggestions for a work around?
Thanks.
I do something like this to record the screen from CI and it always works for me:
set filePath to (path to desktop as string) & "ScreenRecordingFile.mov"
tell application "System Events" to tell process "Simulator"
set frontmost to true
end tell
tell application "QuickTime Player"
activate
set newScreenRecording to new screen recording
delay 1
tell application "System Events"
tell process "QuickTime Player"
set frontmost to true
key code 49
end tell
end tell
tell newScreenRecording
start
delay 15
stop
end tell
export document 1 in (file filePath) using settings preset "720p"
close document 1 saving no
end tell
I've ran into the same problem and found out, that the problem is not in the stop, but in the non-interactive start, so I've tried to start recording (pseudo)interactively and it worked out perfectly.
tell application "QuickTime Player"
activate
new screen recording
activate
tell application "System Events" to tell process "QuickTime Player"
key code 49
end tell
document "Screen Recording" start
delay 10
document "Screen Recording" stop
end tell
It still calls start instead of emulating click, because I haven't found a way to make it work.
Two tricks are needed:
Send a space key to the QuickTime Player before start to avoid the Finishing... dialog being stuck. (credits to #outring)
We need to simulate a mouse click. This is not easy, and we need to do it via CoreGraphics (aka Quartz). We can either write in Objective-C (need compilation), in Python (via PyObjc bridge) or Swift.
Somehow recording starts roughly 2 seconds after the mouse click, so we need to sleep 12 seconds for a 10-second video.
A working script will look like this:
tell application "QuickTime Player"
activate
new screen recording
tell application "System Events" to tell process "QuickTime Player" to key code 49
document "Screen Recording" start
do shell script "python -c 'import Quartz; mouse_location = Quartz.NSEvent.mouseLocation(); [ Quartz.CGEventPost(Quartz.kCGHIDEventTap, Quartz.CGEventCreateMouseEvent(None, mouse_action, mouse_location, Quartz.kCGMouseButtonLeft)) for mouse_action in [ Quartz.kCGEventLeftMouseDown, Quartz.kCGEventLeftMouseUp ] ]'"
delay 12
document "Screen Recording" stop
end tell

Applescript click on save button

I got error; Can’t get button "save" of process "TextEdit".
activate application "TextEdit"
tell application "System Events" to tell process "TextEdit"
keystroke "s" using {command down}
click button "save"
end tell
I was also tring to include like "of window 1" still I can't get this working. Any help will be much appreciated. thanks
why not just talk to the app directly ?
tell application "TextEdit"
tell document 1 to save
end tell
if you must use the GUI you need the correct hierarchy ( but it is best to talk to the app directly)
activate application "TextEdit"
tell application "System Events"
tell process "TextEdit"
keystroke "s" using {command down}
delay 1
click button "Save" of sheet 1 of window 1
end tell
end tell

keystroke "1" using command down - beeps instead of working

I'm writing a simple applescript that should focus an app and click "cmd+1".
This is what I wrote:
tell application "System Events"
tell application process "appname"
--Lobby focus
activate
keystroke "1" using command down
end tell
end tell
But instead of working, there's one beep and the application doesn't even take focus.
How can I solve this?
You can't tell processes to activate. Change it to set frontmost to true:
tell application "System Events"
set frontmost of process "Finder" to true
keystroke "1" using command down
end tell
Or tell the application to activate:
activate application "Finder"
tell application "System Events"
keystroke "1" using command down
end tell
If the application has no open windows, reopen opens a new default window:
tell application "Finder"
reopen
activate
end tell
tell application "System Events"
keystroke "1" using command down
end tell

How do I do while in an AppleScript to wait for a quit action?

I'm trying to send a URL to chrome for viewing flash, quit Safari in the meanwhile so it's not using up memory, and then as soon as I quit Chrome, go back to Safari. It's not predictably going back to Safari after I quit Chrome, so I need help with the repeat loop. I want to run this as a service. Thanks!
property theURL : ""
on run {input, parameters}
tell application "Google Chrome"
activate
end tell
tell application "Safari"
activate
end tell
tell application "System Events"
keystroke "j" using {command down} -- Highlight the URL field.
keystroke "c" using {command down}
keystroke "w" using {command down}
end tell
delay 0.1
tell application "Safari"
quit
end tell
tell application "Google Chrome"
if (count of (every window where visible is true)) is greater than 0 then
tell front window
make new tab
end tell
else
make new window
end if
set URL of active tab of front window to the clipboard
activate
end tell
repeat
if application "Google Chrome" is not running then exit repeat
delay 5
end repeat
tell application "Safari"
activate
end tell
return input
end run
Update! Here's the working script:
property theURL : ""
on run
tell application "Safari"
activate
set theURL to URL of document 1
quit
end tell
tell application "Google Chrome"
activate
if (count of (every window where visible is true)) is greater than 0 then
tell front window
make new tab
end tell
else
make new window
end if
set URL of active tab of window 1 to theURL
activate tab 1
end tell
repeat
tell application "System Events"
if "Google Chrome" is not in (name of application processes) then exit repeat
end tell
delay 5
end repeat
tell application "Safari"
activate
end tell
end run
You could try this...
repeat
tell application "System Events"
if "Google Chrome" is not in (name of application processes) then exit repeat
end tell
delay 5
end repeat
Also I always avoid using keystrokes and other gui scripting stuff if I can avoid it. They're not 100% reliable. As such I suggest you transfer the url like this...
tell application "Safari" to set theURL to URL of document 1
and...
tell application "Google Chrome" to set URL of active tab of window 1 to theURL

How to change space with applescript

I have the following applescript to skip songs in spotify. If I call the script when a fullscreen application is the frontmost, the application will not be visible after the script has finished. It will be in a different space. Is there a way that I can make the frontmost application visible again with applescript?
set front_app to (path to frontmost application as Unicode text)
tell application "Spotify"
next track
end tell
tell application front_app to activate
This probably won't get you anywhere, but you could use this script to loop through all your spaces until you see the application you're targeting...
set front_application to current application
tell application "Spotify" to next track
tell application "Finder" to set collapsed of front_application to false --makes sure the app isn't minimized
repeat
tell application "System Events" to keystroke (ASCII character 29) using {control down}
display dialog "Correct space?" buttons{"OK"} default button 1 giving up after 4 --don't click 'OK' if the current space isn't showing the target application
if gave up of the result is false then exit repeat
end repeat
set front_app to current application
tell application "Spotify"
next track
end tell
tell front_app to activate

Resources