AppleScript to launch and loop a video? - applescript

I need to write an AppleScript so that it will open QuickTime Player, play the movie from the specific file, and set it to loop in full screen. Help please I am a noob at writing AppleScripts.
This is what I have so far but it does not seem to work. :(
tell application "QuickTime Player"
open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
set the looping of movie 1 to true
play movie 1
end tell

The easiest way to do it is probably to assign the value returned by open file to a variable, and then tell that variable (that is, tell that movie) to do what it needs to do.
tell application "QuickTime Player"
set theMovie to open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
tell theMovie
set the presenting to true
set the looping to true
play
end tell
--use this to see what properties can be modified
--get the properties of theMovie
end tell
You can uncomment get the properties of theMovie to see what properties are available to modify.
If that doesn’t work for you, you’ll also need to specify exactly what you mean by “it does not seem to work”. That is, what error occurs, if an error occurs, or what happens differently than what you expect. I’ve verified that the above does work with a movie on my end.

I just had this problem and the solution above did not work for my apple computer, so I modified the script to get it to work. I wanted to the script to launch on boot, which I accomplished by going to System Preferences -> Users -> Login Items.
tell application "QuickTime Player"
set theMovie to open file "Users:danielmcclane:Downloads:startvideo.mov"
tell theMovie
set the looping of theMovie to true
set the present of theMovie to true
play
end tell
end tell

This worked for me. I use it to play video art pieces at the museum I work at. It works.
tell application "QuickTime Player"
activate
open alias "Users:ebowen:Desktop:MOUND_1.32GB_h264.mov"
play the front document
end tell
tell application "System Events" to tell process "QuickTime Player"
set frontmost to true
tell menu bar item 5 of menu bar 1
click menu item "Enter Full Screen" of menu 1
click menu item "Loop" of menu 1
end tell
end tell

Related

How could I use applescript to play keynote slids?

everyone
I try to use applescript to play my keynote slid,but occure error
set thisFile to "/Users/usrname/Desktop/cardtest.key"
tell application "Keynote"
activate
open thisFile
start thisFile from the first slide of thisFile
end tell
this code will open keynote file successfully,but can't run slids.
the error was keynote error : can't make "path" become type "document".
I tried to use:
tell slideshow 1
but another error: slideshow should be the end of sentence, should not have 1.
have no idea why.
You are going to start a POSIX path rather than a Keynote document.
This is exactly what the error is telling you.
You have to use the reference to the opened document
set thisFile to "/Users/usrname/Desktop/cardtest.key"
tell application "Keynote"
activate
set currentDocument to open thisFile
tell currentDocument to start from first slide
end tell

How can I open an MP3 with quicktime player using applescript?

I have the following code to open the files, but they all open with iTunes:
tell application "Finder"
set the_files to get every file of folder ("Macintosh
SSD:Users:myusername:Desktop:DJ:Music:Sort")
end tell
repeat with theItem in the_files
tell application "QuickTime Player"
open theItem
end tell
end repeat
Thanks!
AS syntax can be very misleading. While your open command is inside a tell application … end tell block, that doesn’t necessarily mean it will be sent to that application. If the command’s direct parameter happens to be a reference to objects in another app (in this case, a reference to a document file object in Finder) AS will send it to that app instead.
Use set the_files to get every file of folder (…) as alias list. That will get you a list of AppleScript alias values, instead of a list of Finder references (which any app other than Finder wouldn’t understand anyway).

Dynamic Slideshow using Applescript

I have a folder of images that gets updated from a camera taking pictures periodically throughout the day. I'm trying to write some applescript that will create a slideshow from a folder of images but also update as more are added without having to rerun the script. I started out trying to do quick look but couldn't get that working. Any ideas on how best to tackle this?
UPDATE
this is what I have hacked together so far:
tell application "Finder" to set the_folder to get folder (choose folder)
tell application "Finder" to open the_folder
tell application "System Events"
tell process "Finder"
key code 124
keystroke "a" using command down
keystroke " " using option down
end tell
end tell
I don't believe this works if I add photos behind the scenes though.
This is what I came up with and it works perfectly for what I need.
tell application "Finder" to set the_folder to get folder (choose folder)
tell application "Finder" to open the_folder
tell application "System Events"
tell process "Finder"
key code 124
keystroke "a" using command down
keystroke " " using option down
end tell
end tell
repeat while true
delay 60
tell application "System Events"
tell process "Finder"
keystroke "a" using command down
end tell
end tell
end repeat
A few caveats... since it is using quick look, you can't really do anything on the computer while this is running since it can't have any other app activate while it is running (quick look closes when this happens). Also the repeat section is required to get quick look to pickup the new additions to the directory without losing focus. Pretty nasty stuff, but I couldn't really find another easy way to do it!

AppleScript: open current iTunes track in another program [Riffstation]

I'm new to AppleScript and not programmer, so I'm hoping someone can help me out...
I want to get the current track path in iTunes and open the file in another program [Riffstation]
seems like this should work, but it doesn't:
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Riffstation"
open songLocation
end tell
any help would be greatly appreciated!!!
Riffstation doesn't support AppleScript so you have to ask the Finder to open the file and pass it to Riffstation
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
If you want to ignore .m4p files use
tell application "iTunes" to set {location:songLocation, kind:songKind} to current track
if songKind is not "Protected AAC audio file" then
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
end if

AppleScript -> Activate window of a non-scriptable application

I have opened 2 "Finder" window A & B, A is in the front while B underneath, the following snippet brings B to the front the topmost:
tell application "Finder"
activate
activate window 2
end tell
But for applications that do not support scripting, the code just mentioned won't help.
Any ideas for activating a window of non-scripting application.
You can usually turn to system events in these cases. System events knows about the windows of running processes and you can usually manipulate those windows. Something like this will show you some of the things you can do. Just play around with the code and see if you can do what you want.
tell application "System Events"
tell process "Whatever"
properties of windows
end tell
end tell
EDIT: One of the properties of a window is its "title". So you might be able to use that. This approach uses the fact that many applications have a "Window" menu and under that menu many times the name of the windows are listed and you can switch windows by clicking the approprite menu item. So something like this might work... my example uses TextEdit.
tell application "TextEdit" to activate
tell application "System Events"
tell process "TextEdit"
set windowTitle to title of window 2
click menu item windowTitle of menu 1 of menu bar item "Window" of menu bar 1
end tell
end tell
What is your definition of non-scriptable? Just about everything is scriptable to some degree, but for the sake of an example lets use, does not contain an AppleScript dictionary, e.g. AppName.sdef within its application bundle.
For example, the macOS included Stickies application does not contain the Stickies.sdef file, and when trying to add it to the Library in Script Editor is says, "Unable to add the item because it is not scriptable."
In a case such as this, then System Events is needed to talk to the application process, e.g.:
Example AppleScript code:
if running of application "Stickies" then
tell application "System Events"
tell application process "Stickies"
set frontmost to true
if exists window 2 then ¬
perform action "AXRaise" of window 2
end tell
end tell
end if
Notes:
I've included error handling in the example AppleScript code, which can be removed if you prefer.

Resources