How could I use applescript to play keynote slids? - applescript

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

Related

Simple Applescript - Quicktime Issue Play Song

I'm trying to do a very basic thing using Applescript but I'm having trouble. I am trying to create a very simple Applescript to just open a plain vanilla MP3 file on my desktop with QuickTime Player.
I want to use QuickTime and have it open so user can control it etc.
The basic problem is that the file name or folder path seems to be sometimes randomly causing problems especially when it has spaces in the name or the path folder names etc.
If I double click on any file they all open in QuickTime.
I created a very basic short audio file and saved it with a few different names like:
test1.mp3
test 1.mp3
this is a test.mp3
Then I created this very simple Applescript below.
generally = test1.mp3 will almost always open and start playing, however the other Versions with spaces in the title often produce and error (open thesong line fails i think) like:
The document “test1.mp3” could not be opened.
The file isn’t compatible with QuickTime Player.
error "QuickTime Player got an error: Can’t get document 1. Invalid index." number -1719 from document 1
think this is because it can't open the file.
Any help would be appreciated.
Applescript ...
tell application "Finder"
--varied attempts like this...
set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string
set thesong to "drive:Users:me:Desktop:music:test1.mp3"
set thesong to "drive:Users:me:Desktop:music:this is an audio test.mp3" as string
set thesong to "drive:Users:me:Desktop:test1.mp3" as string
end tell
tell application "QuickTime Player"
activate
open thesong
play document 1
end tell
Also I tried adding delays thinking that QuickTime needed time to open before open / play song - but still have random fails...
tell application "QuickTime Player"
activate
delay 3
open thesong
delay 3
play document 1
end tell
The Finder is not needed and the delays are not needed either.
Assuming the file is on the desktop create a relative HFS path and add the alias keyword after the open command
set theSong to (path to desktop as text) & "test1.mp3"
tell application "QuickTime Player"
activate
set activeDocument to open alias theSong
play activeDocument
end tell
If the file is in the folder music on the desktop the path is
set theSong to (path to desktop as text) & "music:test1.mp3"
In AppleScript, there are differences between a string, a POSIX file («class furl») , and an alias.
When you do set thesong to "drive:Users:me:Desktop:music:test1.mp3" as string that creates a string, which is just plain text. QuickTime Player's open command requires either a POSIX file or an alias, which is why you get an error message (it doesn't know what to do with a plain text string).
While you ultimately need to end up with a POSIX file or alias, you can start with a string and then coerce it to the type you want.
Either of the open commands below should work:
set posixFile to "/Users/you/Desktop/file.mp3" as POSIX file
set aliasFile to ":Users:you:Desktop:file.mp3" as alias
tell app "QuickTime Player"
set theDoc to open posixFile
-- or set theDoc to open aliasFile
play theDoc
end tell

Applescript copy name of selected image in preview

I have several images opened in one Preview window. I'm trying to copy the file name of the selected image in the window.
Currently, I'm using
tell application "Preview" to activate
tell application "System Events" to keystroke "c" using command down
This does not work, probably because it copies the file and its path (I only need the file name as string)
thanks a lot
Maybe this is along the lines of what you are looking for?
tell application "Preview"
set thePath to path of document of front window as POSIX file as alias
end tell
tell application "Finder"
set theName to name of (get properties of thePath)
end tell
set the clipboard to theName
set the text item delimiters to "/"
get the path of the front document in application "Preview"
--> "/Users/CK/Pictures/Screenshots/Screen Shot 2018-03-29 at 16.06.jpg"
get the last text item of the result
--> "Screen Shot 2018-03-29 at 16.06.jpg"
--OR--
get the path of the front document in application "Preview"
tell application "System Events" to get the name of the file result
--> "Screen Shot 2018-03-29 at 16.06.jpg"
--THEN--
set the clipboard to the result

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).

AppleScript to launch and loop a video?

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

Opening files in Photoshop with an applescript droplet

I have a problem. I am a complete Applescript novice and I am trying to simply open 3 files from my desktop into Photoshop CS4 using a droplet, but when I drop the files I get This error:
Can't get alias "Macintosh HD:Users:nazkav:Desktop:Kav1_jpg"
This is the code I'm using:
on open these_files
repeat with i from 1 to the count of these_files
set this_file to item i of these_files
my image(this_file)
end repeat
end open
on image(the_image)
tell application "Adobe Photoshop CS4"
activate
open the_image as JPEG
end tell
end image
I hope somebody can help
Thanks in advance
Kavin

Resources