Applescript simple open save file snippet? - applescript

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.

Related

Issue Moving Files in AppleScript

I'm having trouble with the following line of AppleScript:
move file currentFile to POSIX file "/Users/UserName/Desktop/FolderName"
I've found that it works in one script but not in another, and I can't figure out why. In both scripts, currentFile is defined as an item in a list.
I've been trying different workarounds for hours but I can't get anything to work. Is there any reason why this code would work in one circumstance but not in another?
Thank you!
AppleScript doesn't know how to move a file.
It has to ask the Finder or System Events. In case of the Finder the syntax is pretty easy because the desktop folder of the current user is the root folder of the Finder
tell application "Finder"
move file currentFile to folder "FolderName"
end tell
currentFile must be an HFS path (colon separated).
In case of System Events the syntax is slightly different and System Events supports also POSIX paths
tell application "System Events"
move file currentFile to folder "FolderName" of desktop folder
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

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

Listing folder in /Users

Using Applescript, I have been able to successfully list the folders on my desktop as a selection using this code:
set the_folder to (path to desktop)
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list folder names
However, when I attempt to do the same for the /Users folder:
set Users to "/Users"
set the_folder to Users
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list foldernames
It returns this error: error "Can’t get entire contents of \"/Users\"." number -1728 from «class ects» of "/Users"
Searched on that error, but not finding much info. Thanks for any help you can give me with this one.
The error occurs because the Finder does not support slash separated POSIX paths.
But there is a simpler solution. path to users folder return an alias reference to the folder /Users which can be used directly.
set the_folder to path to users folder
tell application "Finder"
set foldernames to name of every folder of entire contents of the_folder
end tell
set theChosenOne to choose from list foldernames
Caveat: Be aware that entire contents is very slow. After 2 minutes you will get an Apple Event timed out error. You might wrap the Finder tell block in a with timeout block. However I'd recommend find or mdfind of the shell which are incredibly much faster. And most likely you will get also an access privileges violation error.

How do I use applescript to name a folder by pasting from the clipboard

I work in graphic design and want to create an script for indesign that will automatically:
open a specified document template.
Create a new project folder.
Name that folder with text from the clipboard.
Save the newly opened document to the newly created folder and name that document with the same text from the clipboard.
I am very new to Applescript so type very slowly and use small words so that I can understand.
Here is what I have come up with in the way of code so far:
tell application "Adobe InDesign CS5"
set myDocument to open "cm:Graphic_Design:Design Studio Templates:Brochure_042012_001:Brochure_042012_001.indt"
end tell
tell application "Finder"
make new folder at folder "Work" of folder "Graphic_Design" of disk "cm" with properties {name:"untitled folder"}
set name of folder "untitled folder" of folder "Work" of folder "Graphic_Design" of disk "cm" to pbpaste
end tell
Try:
tell application "Finder" to set newFolder to make new folder at "cm:Graphic_Design:Work" with properties {name:(the clipboard as text)}
tell application "Adobe InDesign CS5"
tell active document to save saving in (newFolder as text)
end tell

Resources