Export active page to PDF (AppleScript + InDesign) - applescript

I have an AppleScript that exports the active document in InDesign to a PDF on my desktop.
--this script exports all opened InDesign document as PDFs
set my_destination to (path to desktop) as string
tell application id "com.adobe.InDesign"
activate
--next line collects all current PDF export presets
set my_pdf_export to get the name of every PDF export preset
--next line makes you choose which preset to use for ALL opened InDesign documents
set my_pdf_choice to (choose from list my_pdf_export) as string
--loop starts here
repeat with this_doc in (active document)
--next line gets the name of the active InDesign document
set doc_name to get name of this_doc
--next 3 lines perform the actual PDF export
tell this_doc
export format PDF type to my_destination & (characters 1 thru -6 of doc_name) & ".pdf" using my_pdf_choice without showing options
end tell
end repeat
end tell
The script prompts for a PDF preset selection before exporting.
I'd like the script to export only the active page of the active document.
I've tried a couple things like replacing "active document" with active page", however I am not too knowledgable about AppleScript.
Any ideas?

It looks like you got your code from This Macscripter question, and the code is already in that script. You just need to set the page range of InDesign's PDF Export Preferences
tell PDF export preferences
set page range to "1, 3-5"
end tell
Just make sure to set it back at the end, because this is a persistent application setting.
tell PDF export preferences
set page range to all pages
end tell

Related

Applescript to Control Photoshop Save Dialog Box

How are you?
I've created an applescript automation to save files in .JPG while the Save Dialog Box is open. (So I can control the name of the saved files)
Is there a way to control the Save Dialog Box of Photoshop?
What I want to happen is: Upon appearing of save dialog box
-Command + a will happen (to select all characters)
-Press delete (to delete all characters selected)
-Delay 8 seconds = Enough time for me write my own file name.
-Automation will press return to save the file under my own written file name.
I tried reading Photoshop's dictionary at Script editor but found no results for Controlling Photoshop's save dialog box.
I tried doing system events to do command a + press delete + delay 8
seconds and pressing return but that event only happens after the save
dialog box disappears instead of doing that on the actual save dialog
box.
My Photoshop is: CS6 Extended
Os: El Capitan
Thank you very much.
You should avoid using GUI scripting : each time Adobe (or Apple) will change the graphic display of the 'save as' dialog box, your script may no longer work.
Instead, use a 2 step approach : 1) get the false name and path using a standard 'choose file name' and then use this file to save using 'save' command in Photoshop. This script assume there is a current open document.
Please update 'Adobe Photoshop CS3' with your version (mine is a bit old, but good enough to test !).
Also, the default folder could be adjusted for your needs (here = Desktop).
tell application "Adobe Photoshop CS3"
set docRef to the current document
set docName to name of docRef -- current name will be use as default new name
set file2save to ((choose file name default location (path to desktop) default name docName) as string)
save docRef in file file2save as JPEG appending lowercase extension with copying
end tell
Note 1: you can improve that script by checking the extension typed in file2save variable, and, if missing, the script can add the correct extension (i.e. 'jpg').
Note 2: Adobe made some changes in 'open ' command between version CS3 and CS6. I hope these changes do not affect the 'save' command.
This is a code to what you specified also it includes open the save box:
tell application "Adobe Photoshop CS6"
activate
tell application "System Events"
keystroke "s" using {command down, shift down}
delay 1
keystroke "a" using {command down}
delay 0.1
key code 51
delay 8
keystroke return
end tell
end tell

Apply to Only 1 current document FInd and change

Hi Below is apple script which does find and change operation in indesign document.But this script does not execute and gives a error.
"Adobe InDesign CS6 got an error: Can’t set find text preferences of document 1 to nothing."
script is
tell application "Adobe InDesign CS6"
tell front document
set find text preferences to nothing
set change text preferences to nothing
--Letter Z--
set case sensitive of find change text options to true
set abbreviation to ".<005A>"
set thinspace to ". <005A>"
set find what of find text preferences to abbreviation
set change to of change text preferences to thinspace
change text
set find text preferences to nothing
set change text preferences to nothing
end tell
end tell
Please suggest any one.
This should run for only for opened document. when front document is removed this script runs.
I could not sort out the error.
The find text preferences and change text preferences belong to the application, not to a document. Try this
tell application "Adobe InDesign CS6"
if (count documents) is 0 then return
set find text preferences to nothing
set change text preferences to nothing
set case sensitive of find change text options to true
set abbreviation to ".<005A>"
set thinspace to ". <005A>"
set find what of find text preferences to abbreviation
set change to of change text preferences to thinspace
tell document 1
change text
end tell
set find text preferences to nothing
set change text preferences to nothing
end tell

Change the color of text by using applescript

I am writing some text in to word file i want to change the color of that text any one can help on that one plz.
I want to print the 'message' from following script in red color.
Here is the Script:
set message to "mostly these windows are popup in application"
on ResultCreationFuction(message)
try
set text_to_save to message as text
tell application "System Events"
tell application "Finder"
set sortedList to sort (get files of folder "SofTestAutomationResult" of desktop) by modification date
set FileCount to get count of sortedList
set theFile to (item FileCount of sortedList) as alias
end tell
set file_ref to open for access theFile with write permission
write (text_to_save & return) to the file_ref starting at eof
close access file_ref
delay 2
end tell
end try
end ResultCreationFuction
Some Details:
The file is word which is all ready present on above location having name "10.012.2014_17_4_20.doc" (the name of .doc file is not fix)
What you are attempting is the wrong way to do it.
To manipulate content like that, including formatted text (not plain
text), you need to work within, ideally, a well-scriptable app, like
Pages (or Word, perhaps, but I don't have that on the machine I'm
writing this from).
Don't use System Events if you don't need to. Use the apps with the appropriate AppleEvents/dictionary, etc. If you don't know what I'm talking about, you need to take advantage of the infinite resource known as the web.
"Fuction" is just bad form.
I would suggest doing a lot more reading up on how AppleScript works (or scripting in general), but to start you out, here is a script I just wrote in pages which sets the color of a specific word of the open document after putting text in there:
tell application "Pages"
set body text of document 1 to "hello there mister fancy pants"
set color of word 3 of body text of page 1 of document 1 to {64614, 0, 111}
end tell
If you have Pages, try this by starting with a blank page and running this script. Obviously, you could get rid of "word 3 of" in the 2nd line, and the whole body text will be red.
I hope this makes sense and is of help.
[edit]
I should mention that even TextEdit is scriptable and can open Word documents. Here's an example using TextEdit:
tell application "TextEdit"
set text of document 1 to "hello mister fancy pants"
set color of words 2 thru 3 of text of document 1 to {65535, 0, 0}
end tell
There is a little danger of non-Word apps losing formatting of Word files. But it just seems you are attempting something very simple, and I'm not sure if Word is really necessary here.
You can't add color using the write to eof. You should open the document in Word and then insert the line and add the color. Here's a script that should demonstrate how:
set text_to_add to "mostly these windows are popup in application"
set theFile to ((path to desktop folder) & "10.012.2014_17_4_20.doc") as string
tell application "Microsoft Word"
set theFile to theFile as string -- assuming theFile is an alias or :: path
open file theFile
tell active document
set endOfDoc to end of content of text object -- insert the text to end of document
set theRange to create range start (endOfDoc - 1) end endOfDoc
insert text text_to_add at theRange
set myRange to create range start endOfDoc end (endOfDoc + (length of text_to_add))
set color index of font object of myRange to red
save
end tell
end tell

How can I automate a keynote workflow to flatten slides into image slides for export to .ppt

I always design my presentation slides in keynote (because I find it easier and more pleasant to work with), though they often need to be presented on a windows machine running PowerPoint.
In order to avoid issues with fonts, formatting, etc., I always use the following effective workflow:
Design the slides in keynote, often using images and text.
Export the slides as jpg files to a folder on the desktop.
Open a new keynote presentation.
Drag the jpg files into the slide navigator. This creates an image slide of each jpg.
export the new presentation to a .ppt file.
Is there a way I can automate this workflow? I'd love to collapse steps 2-5 into a single step!
Here's the AppleScript that does this (work on Keynote version 6.2, not on version 5):
tell application "Finder" to set f to (make new folder) as text -- create a temp folder to export images
tell application "Keynote"
tell front document
export to (file f) as slide images with properties {image format:JPEG, compression factor:95}
set {h, w, fPath} to {height, width, file of it}
end tell
tell (fPath as string) to if it ends with ".key:" then
set newFile to (text 1 thru -6) & ".ppt"
else
set newFile to it & ".ppt"
end if
set jpegs to my getImages(f)
set newDoc to make new document with properties {width:w, height:h}
tell newDoc
set mSlide to last master slide -- blank
repeat with thisJPEG in jpegs
set s to make new slide with properties {base slide:mSlide}
tell s to make new image with properties {file:thisJPEG}
end repeat
delete slide 1
export to (file newFile) as Microsoft PowerPoint
close saving no
end tell
end tell
tell application "Finder" to delete folder f -- delete the temp folder
on getImages(f)
tell application "Finder" to return (files of folder f) as alias list
end getImages
Important:
the slideshow must be already open in Keynote before running the script.
And the slideshow must be already saved, because the script use the path of the front document to save the PPT file in the same folder.
--
Updated: to choose location of the new file
set v to ("Volumes" as POSIX file) as alias
tell application "Finder" to set f to (make new folder) as text -- create a temp folder to export images
tell application "Keynote"
tell front document
export to (file f) as slide images with properties {image format:JPEG, compression factor:95}
set {h, w, tName} to {height, width, name of it}
end tell
tell tName to if it ends with ".key" then
set newName to (text 1 thru -5) & ".ppt"
else
set newName to it & ".ppt"
end if
set jpegs to my getImages(f)
activate
set newFile to choose file name default name newName default location v with prompt "Select the folder to save the PPT file"
set newDoc to make new document with properties {width:w, height:h}
tell newDoc
set mSlide to last master slide -- blank
repeat with thisJPEG in jpegs
set s to make new slide with properties {base slide:mSlide}
tell s to make new image with properties {file:thisJPEG}
end repeat
delete slide 1
export to (newFile) as Microsoft PowerPoint
close saving no
end tell
end tell
tell application "Finder" to delete folder f -- delete the temp folder
on getImages(f)
tell application "Finder" to return (files of folder f) as alias list
end getImages

How to read a file and open Safari with the read result with Mac (AppleScript)?

I need to open multiple Safari (or open the tab is OK) based on the read result.
For example, if a file has
http://a.com
http://b.com
I want to open a.com and b.com using Safari.
How can I do that with Mac/AppleScript?
Maybe I can run python calling "open -a Safari "http://a.com", but I guess AppleScript is the tool for this kind of job.
not sure about python but this will read a text file and open windows let me see if I can get tabs for you though
set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls"))
repeat with aline in locations
if length of aline is greater than 0 then
tell application "Safari"
make new document at end of documents
set URL of document 1 to aline
end tell
end if
end repeat
EDIT:
Ok this is better and it opens them in tabs of a single window
set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls"))
tell application "Safari"
activate
set adoc to make new document
end tell
repeat with aline in locations
if length of aline is greater than 0 then
tell application "Safari" to make new tab at end of window 1 with properties {URL:aline}
end if
end repeat
New Addtion
this is yet another way based on regulus6633's post in conjunction with mine
set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls"))
repeat with aLocation in locations
tell application "Safari" to open location aLocation
end repeat
If you want it to specifically open the links in Safari then mcgrailm's solution is good. However, you don't need the Finder for the first part so take that code out of the Finder tell block. There's no need to tell the Finder to do something that applescript can do itself.
However, you probably want to open the links in whatever browser is the user's default browser. It may be Safari or Firefox etc. You can do that with the "open location" command. So something like this is probably what you want...
set theFile to choose file with prompt "Pick text file containing urls"
set locations to paragraphs of (read theFile)
repeat with aLocation in locations
try
open location aLocation
end try
end repeat

Resources