Monday, April 27, 2015

>_automatic: Automator Workflows

This is week 2 of >_automatic and we are creating some interesting Automator workflows. Throughout the week we will continue to post some of the workflows we find to be helpful.

Change Image Type - Workflow

This is a converter to use when you want to change a JPG to PNG for example, or any other number of conversion combinations!


Convert Keynote to PDF - Service

A number of teachers at KIS have requested this. A conversion, however it requires AppleScript. This nice thing is this is only a 2 Action thing, and the second is an optional Display Notification. 


You will need to cut and paste the following AppleScript into the Run AppleScript action. 

property exportFileExtension : "pdf"
property useEncryptionDefaultValue : true

-- THE DESTINATION FOLDER 
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as movies folder, pictures folder, desktop folder)
set the defaultDestinationFolder to (path to documents folder)

set usePDFEncryption to useEncryptionDefaultValue
tell application "Keynote"
activate
try
if playing is true then tell the front document to stop
if not (exists document 1) then error number -128
if usePDFEncryption is true then
-- PROMPT FOR PASSWORD (OPTIONAL)
repeat
display dialog "Enter a password for the PDF file:" default answer ¬
"" buttons {"Cancel", "No Password", "OK"} ¬
default button 3 with hidden answer
copy the result to ¬
{button returned:buttonPressed, text returned:firstPassword}
if buttonPressed is "No Password" then
set usePDFEncryption to false
exit repeat
else
display dialog "Enter the password again:" default answer ¬
"" buttons {"Cancel", "No Password", "OK"} ¬
default button 3 with hidden answer
copy the result to ¬
{button returned:buttonPressed, text returned:secondPassword}
if buttonPressed is "No Password" then
set usePDFEncryption to false
exit repeat
else
if firstPassword is not secondPassword then
display dialog "Passwords do no match." buttons ¬
{"Cancel", "Try Again"} default button 2
else
set providedPassword to the firstPassword
set usePDFEncryption to true
exit repeat
end if
end if
end if
end repeat
end if
-- DERIVE NAME AND FILE PATH FOR NEW EXPORT FILE
set documentName to the name of the front document
if documentName ends with ".key" then ¬
set documentName to text 1 thru -5 of documentName
tell application "Finder"
set exportItemFileName to documentName & "." & exportFileExtension
set incrementIndex to 1
repeat until not (exists document file exportItemFileName of defaultDestinationFolder)
set exportItemFileName to ¬
documentName & "-" & (incrementIndex as string) & "." & exportFileExtension
set incrementIndex to incrementIndex + 1
end repeat
end tell
set the targetFileHFSPath to (defaultDestinationFolder as string) & exportItemFileName
-- EXPORT THE DOCUMENT
with timeout of 1200 seconds
if usePDFEncryption is true then
export front document to file targetFileHFSPath ¬
as PDF with properties {password:providedPassword}
else
export front document to file targetFileHFSPath as PDF
end if
end timeout
on error errorMessage number errorNumber
if errorNumber is not -128 then
display alert "EXPORT PROBLEM" message errorMessage
end if
error number -128
end try
end tell

-- SHOW THE NEW MOVIE FILE
tell application "Finder"
activate
reveal document file targetFileHFSPath
end tell


Now press the Hammer icon in the Run AppleScript action to verify that the script is good! 


Now SAVE your Service. Call it 'Keynote to PDF or something similar. 

To test it, select a Keynote from your Finder, right-select, Go down to Services and select your 'Keynote to PDF' service. 



Convert Keynote Slides into individual PNG images - Workflow

This is a Workflow, but could easily be re-jigged as a Service if you prefer that method. This workflow in any case takes a Keynote Presentation, and kicks each slide out into a folder (set to land in your Pictures Folder) as a PNG converted image. 

There are only 2 Actions, with the second action involving a dump of some Apple Script into an Action to make it work. 


Here is the Apple  Script you need (copy paste all of the script in purple below):
(See https://iworkautomation.com/keynote/document-export.html)

property exportFormat : "PNG" -- "TIFF" "JPEG" "PNG"
property includeSkippedSlides : false
property compressionFactor : 1.0

-- THE DESTINATION FOLDER 
-- (see the "path" to command in the Standard Additions dictionary for other locations, such as documents folder, movies folder, desktop folder)
set the defaultDestinationFolder to (path to pictures folder)

tell application "Keynote"
activate
try
if playing is true then tell the front document to stop
if not (exists document 1) then error number -128
-- DERIVE NAME FOR NEW FOLDER FROM NAME OF THE FRONT DOCUMENT
set documentName to the name of the front document
if documentName ends with ".key" then ¬
set documentName to text 1 thru -5 of documentName
-- CREATE AN EXPORT DESTINATION FOLDER
-- IMPORTANT: IT’S ADVISED TO ALWAYS CREATE A NEW DESTINATION FOLDER, AS THE CONTENTS OF ANY TARGETED FOLDER WILL BE OVERWRITTEN
tell application "Finder"
set newFolderName to documentName
set incrementIndex to 1
repeat until not (exists folder newFolderName of defaultDestinationFolder)
set newFolderName to documentName & "-" & (incrementIndex as string)
set incrementIndex to incrementIndex + 1
end repeat
set the targetFolder to ¬
make new folder at defaultDestinationFolder with properties ¬
{name:newFolderName}
set the targetFolderHFSPath to targetFolder as string
end tell
-- EXPORT THE DOCUMENT
if exportFormat is "PNG" then
-- EXPORT THE FRONT DOCUMENT TO PNG IMAGES
export front document as slide images to file targetFolderHFSPath with properties ¬
{image format:PNG, skipped slides:includeSkippedSlides}
else if exportFormat is "JPEG" then
-- EXPORT THE FRONT DOCUMENT TO JPEG IMAGES
export front document as slide images to file targetFolderHFSPath with properties ¬
{image format:JPEG, skipped slides:includeSkippedSlides ¬
, compression factor:compressionFactor}
else if exportFormat is "TIFF" then
-- EXPORT THE FRONT DOCUMENT TO TIFF IMAGES
export front document as slide images to file targetFolderHFSPath with properties ¬
{image format:TIFF, skipped slides:includeSkippedSlides ¬
, compression factor:compressionFactor}
end if
on error errorMessage number errorNumber
display alert "EXPORT PROBLEM" message errorMessage
error number -128
end try
end tell

-- OPEN THE DESTINATION FOLDER
tell application "Finder"
activate
open the targetFolder

end tell

When you have copy/pasted this script into the Run AppleScript action, press the hammer button to configure it (which also checks for errors)....



Select a Keynote (from the 'Get Specified Finder Items' action) and press RUN to test it.

Convert Videos (that land in Dropbox > Camera Uploads folder) - Folder Action

A handy Folder Action that automatically converts uploaded video, as seen below, for iPad, iPhone, AppleTV etc. Very versatile.

Convert images to .png - Workflow

We find this one very useful, especially when wanting to upload an image to a web or blog site, and not have the colour profile messed with. PNG is the answer to that irksome issue, and this little workflow simply automates it for us. 

Reduce the size of PDF files - Workflow

Had a PDF document and tried to send via email only to have it bounce because it exceeds the MB limit? Gone to reduce file size, only to see all the quality stripped out of the document as well? This is a beautiful workflow that will drastically reduce the file size..with little to no discernible difference in document quality. Adding in then additional 'Create New Mail item and add the reduce PDF to it as an attachment is of course optional (depending on whether you use Mail or not).

You will need to set up the Quartz filter first.

Option: Add your 'Reduced File Size PDF to a new Mail message...automatically:


Batch Printing - Workflow

This is actually faster than a manual print workflow. Simply select all of your documents and arrange the print queue (drag and drop the selected Specified Finder Items); have your default printer saved (do this when you make the Workflow), and then hit RUN. 


PDF Splitter - Worlflow

Scenario: you have been sent or downloaded a unit plan or unit and only want specific pages from it. This little workflow will take a multi-page PDF and split it into separate PDF files (one for each page). You can the trash the unwanted material. The companion to this Workflow is the PDF Combiner, which does the opposite: it takes the wanted pages and stitches them together to create a single (but edited selection) PDF file. 


PDF Combiner - Workflow

The promised companion to the PDF Splitter is this little gem:

Wrap Text in Quotes - Service

This is a very simple 'service', and therefore differs from all the above examples. A service can be accessed by right selecting on on object - in this case a text passage. There is only 1 action, and it's 'Run AppleScript'. Copy and paste the script below:


The AppleScript is:


on run {input, parameters}
    return "\"" & (input as string) & "\""
end run

The 'Service receives selected text' setup is important to get right. Make sure you check the box as shown. DONE!

Notice 'Wrap in Quotes Service' in the screenshot below? Select text from anywhere and try it yourself. 

Create a Thumbnail version of an Image - Service

Need to create a low resolution copy of an image to use as a personal avatar on any number of social media like sites? Twitter, Facebook, Instagram etc etc? There is no need to get hassled by the need to come up with a small image using a photo editing App. Just create this Automator Service and it's easy to create the thumbnail image you need. This is a Service, so go to File > New > Service. Here's the rest:

Now File > Save your new Service and call it something like 'Thumbnail This'.

To use this, simply right-select the image from within the Finder and 'Thumbnail This' will be there to choose:

Attach file(s)/folder(s) to a New Mail message - Service

Again, another 'Service', but a super useful one for those who use the native Mail app on their Mac. I like this simple little service because it means I can select any file/folder(s) and instantly have them open up as an attachment to a new email. Quick and easy to make, and use time and time again.





Feel free to download these workflows from our shared folder.


Featured

Popular Posts