Export Keynote slides to images with AppleScript - applescript

I have Keynote slides and I want automatically export them to images for further uploading to server using AppleScript. I've tried to manage it:
tell application "Keynote"
set doc to open "full-path-to-.key"
save doc -- this line didn't help
export doc to file "full-path-to-folder" as slide images
end tell
This script terminates with
error "Keynote got an error: The document “...” could not be exported as “full-path-to-folder”. Your most recent changes might be lost." number 6
Why?

I had a closer look at this exporting documents samples and ran into a problem with referencing a folder I want export my slides to. Then I've found that thing about it with a sample
set thePath to alias "Macintosh HD:Users:yourUserName:Desktop:"
So this one works properly:
tell application "Keynote"
set doc to open "/absolute/path/to/slides.key"
export doc to alias "Macintosh HD:Users:myUserName:further:path" as slide images with properties {image format:PNG}
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

Open Photoshop file in same directory as AppleScript

I am trying to automate label generation from MS Excel into Photoshop using AppleScript. I can get all the data from Excel just fine, however getting that data into a predefined Photoshop document causes problems.
Specifically, I am unable to get Photoshop to open the template file which is located in the same folder as the AppleScript itself. I have tried numerous ways, including using a tell finderblock like this
tell application "Finder"
set myFolder to container of (path to me) as text
end tell
set template_path to myFolder & "CC.psd"
tell application "Adobe Photoshop"
open template_path
end tell
What sort of magic do I need to perform?
PS: Currently this is running on my local drive, however it would be awesome if it would work on network volumes as well.
Thank you
Tobias Timpe

Opening a Keynote Presentation using AppleScript (Keynote 6.5.2)

I am trying to see if i can change the text of some slides inside a keynote presentation that has already been created but i am having problems just opening it to begin with.
here is my current simple applescript:
set thisFile to "Users/myUserName/Desktop/KeynoteAppleScript.key"
tell application "Keynote"
activate
open thisFile
show slide 1
end tell
I get an error stating that the file I am trying to open :
"Users/myUserName/Desktop/KeynoteAppleScript.key" couldnt be opened
because there is no such file".
Thats obviously not correct, it is there and the i have double checked the name of the file to verify.
I am using Keynote 6.5.2
Script Editor Version 2.7, AppleScript 2.4
What am I doing wrong here?
Try adding a leading fwd slash to the path
e.g,
set thisFile to "/Users/myUserName/Desktop/KeynoteAppleScript.key"
I needed to do this to get it opening on 10.8, Keynote 5.3
ALSO..
When in doubt with a file path, try dragging the file from the desktop to the script window and it will insert a correct path.

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

Applescript simple open save file snippet?

I just need a snippet to open and then save a file. It's an illustrator PDF with linked artwork, problem being the linked files do not update unless I open then save the file and I am having to do this sooooo many times it's making my brain explode.
Should be straightforward. I tested the following snippet in Illustrator CS3 (13.0.2) on Mac OS X 10.6.8.
set theFiles to choose file with prompt "Select the files" of type {"pdf"} with multiple selections allowed
tell application "Adobe Illustrator"
repeat with theFile in theFiles
open theFile without dialogs
save current document in theFile as pdf
end repeat
end tell
The choose file command (which prompts the user to locate one or more files) is just one way of obtaining a list of files. You could just as well use
tell app "Finder" to set theFiles to every document file of folder "Macintosh HD:Full:Path:To:Your:Folder" whose file type begins with "pdf"
if you want to get all PDF files inside a specific folder.

Resources