I have a templated Keynote file with some slides and all the slides each have 2 shapes in them. I want to be able to say something like, "hey give me shape 2 of slide 2". The purpose of this, is so that i can add text items directly to that shape. below is the code that I have right now.
I am using the latest Keynote 6.5.2 & Yosemite.
tell application "Keynote"
activate
tell document 1
set anniversary to "Anniversaries"
set myShape to shape 2 of slide 2
tell myShape
set thisTextItem to make new text item with properties {object text:anniversary}
#log thisTextItem
tell thisTextItem
set the size of its object text to 144
set the color of its object text to "blue"
end tell
end tell
end tell
end tell
I can tell slide 2 by itself and of course i get a big text item for slide 2 with text "Anniversaries" and colored blue but its only slide 2... not within shape 2 of slide 2.
With this code it gives me a pop up error when running the script:
Result:
error "Keynote got an error: Can’t make or move that element into that
container." number -10024
what does this mean? do i not have access to shapes within slides?? Any help/info/examples of setting text within a shape that is within a slide would be beneficial. Thanks!
You can set the properties of the text in a shape, you can't insert a text item object in a shape.
tell application "Keynote"
tell document 1
tell shape 2 of slide 2
set object text to "Anniversaries"
tell object text
set it's size to 44
set it's color to {0, 0, 65535} -- blue
end tell
end tell
end tell
end tell
Related
I'm nearing the end of finishing an application that uses Google Vision to identify articles of clothing, and automatically crop to the article in Photoshop.
The first script I have goes through all of the open images and grabs their dimensions and file paths. Those are then passed to my application to do the rest of the magic.
I ran into an issue where it just kept cropping the same image over and over again. After a bit of debugging I realized that this is due to the fact that it will only crop the image that is "active" in photoshop.
So, I'm faced with the task of needing to call another script that sets the next tab as the active document in PS before hitting the crop function.
I was hoping for something easy like:
tell application "Adobe Photoshop 2020"
set currentDocs to documents
set currentDoc to next item of currentDocs
end tell
Well, that doesn't work...
tell application "Adobe Photoshop 2020"
set currentDocs to documents
-- set myList to {}
repeat with n from 1 to count of currentDocs
set currentDoc to item (n + 1) of currentDocs
end repeat
end tell
This works, but errors after the last tab because it goes out of bounds. (not sure how to stop that?) And the fact that it's in a loop doesn't help either. I just need a simple script that sets the currentDoc to the NEXT open image. Then I Can crop, move to the next image, crop, etc.
But it also needs to know the last tab so it doesn't go back through the images.
Use the repeat with loopVariable (in list) syntax instead.
Then set current document in each turn of the loop.
For example, the following loops over all open documents and crops them to 100 x 100 pixels:
tell application "Adobe Photoshop 2020"
repeat with doc in documents as list
set current document to doc
crop doc bounds {0, 0, 100, 100}
end repeat
end tell
Using AppleScript, I want to alter the x and y position of a particular image on every slide of a Keynote document. Once Keynote is running and activated, the following code works...
tell the front document
set the current slide to slide 1
tell the current slide
set thisImage to image 1
set position of thisImage to {10,10}
end tell -- current slide
end tell -- front document
... but it's too fragile. If my image is not the first one ("image 1") then I'll be changing the position of the wrong object. I can't find anything in the scripting dictionaries or in on-line examples about expressing an object specifier for a particular image. I tried several variations on things like...
set thisImage to image with file name "my-file.png"
... to no avail. Any and all advice is appreciated. Thanks!
This works in Keynote 8.2, but to be honest, I'm not sure why.
set thisImage to image {name:"my-file.png"}
However, if you want to then ask thisImage what its name is, you have to ask for its file name, e.g.…
file name of thisImage
Every time I use any presentation software, I somehow like them all less.
You have some redundancy (around 'current slide') so here is my take:
tell slide 1 of the front document
set thisImage to image {name:"my-file.png"}
set position of thisImage to {10, 10}
end tell
Finally, since your objective is to cycle through every slide in the deck, you could try this:
tell front document
repeat with i from 1 to count of slides
tell slide i to set position of image {name:"my-file.png"} to {10, 10}
end repeat
end tell
Upon further review, the earlier answer doesn't work, or no longer works. Apparently the name specifier...
set thisImage to image {name:"my-file.png"}
... doesn't actually specify a name in that manner. Here is my ugly workaround:
tell the current slide
set imageCount to the count of images
repeat with i from 1 to imageCount
set thisImage to image i
if file name of thisImage = "myTargetFile.png" then
set position of thisImage to {10, 10}
exit repeat -- Ugly programming, look away.
end if
end repeat
end tell
I currently have an AppleScript that makes small changes to text boxes in an indesign document. The script goes page by page, and if an applied object style is called a certain name and it contains a certain character, it will apply a paragraph style. Here's an example of my script:
tell application "Adobe InDesign"
repeat with x from 1 to count pages
set ThisPage to page x
tell ThisPage
if exists (text frames whose (name of applied object style is "PriceBox" and contents contains "/$")) then
set myFrames to (text frames whose (name of applied object style is "PriceBox" and contents contains "/$"))
tell myFrames
repeat with r from 1 to count items
set applied paragraph style of paragraphs of item r of myFrames to "2forPrice"
end repeat
end tell
end if
end tell
end repeat
end tell
What this does is it goes to the first page of a document, and if there is a text box that is called "PriceBox" and the text box has the characters "/$" in it, it will change the paragraph style to a named style "2forPrice".
This works great when there is 1 "listing" on each page. I am trying to make this work where there are multiple groups of listings and make the script go to each and every group of boxes separately and run the script. Any way to tell if this can be done by group, rather than by page?
Thank you for your help!!
UPDATE:
Here are the screenshots of what it does, I skipped a few steps to make it work, but I rather use groups of boxes.
Picture1: This is what's considered a "group", I want to put all these boxes in one group.
Picture2: Here is how all the groups are laid out on one page
Picture3: Take a look at the changes to the prices if it's a "2for", for example 2/$6
I want my script to go group by group, instead of page by page, to do the if statement and change the paragraph style. Thanks again for your help!
#Ted: Depending on how well an app’s Apple Event Object Model is implemented, you should be able to do all that in a single command:
tell application "Adobe InDesign"
tell front document
tell pages
tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
set applied paragraph style of paragraphs to "2forPrice"
end tell
end tell
end tell
end tell
(Tip: Apple event IPC is RPC + queries, not OOP.)
[ETA] As commenter below notes, this won’t work on grouped text frames, so here’s a recursive variation that will:
to walkGroups(groupRef)
tell application "Adobe InDesign CS6"
tell groupRef
tell (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
if it exists then
set applied paragraph style of paragraphs to "2forPrice"
end if
end tell
repeat with subgroupRef in groups
my walkGroups(subgroupRef)
end repeat
end tell
end tell
end walkGroups
tell application "Adobe InDesign CS6"
my walkGroups(front document)
end tell
I think you can use "page items" of the page. If there is a group, it will count as a page item. You will then have to programmatically inspect each group for text frames.
Eg, if there are 3 text frames and one group of 2 text frames, the text frame count for the page will be 3, but the page items count will be 4 (the three ungrouped text frames plus the one group of 2 text frames.
ONE-LINER / STORY approach
As you can see, searching for text frames by scouring pages, spreads, paste boards, groups, etc. can be difficult. The script API doesn't have a command for "give me all text frames in the layout regardless of where they are".
The workaround here is to use the story object. If you ask InDesign to give you a list of all stories (or text flows) in a layout, you'll get them regardless of where they may exist within the layout.
The example below starts with all stories that are associated with a text frame and then matches only the stories where the text frame's object style is "test". It then applies a paragraph style to the paragraphs of those stories.
tell application "Adobe InDesign CC 2018"
set applied paragraph style of paragraphs of (stories of document 1 whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$") to "Body Text"
end tell
IF NESTED TELLS ARE PREFERRED
tell application "Adobe InDesign CC 2018"
tell document 1
tell (stories whose class of (object reference of item 1 of text containers) is text frame and name of applied object style of item 1 of text containers = "test" and contents contains "/$")
set applied paragraph style of paragraphs to "Body Text"
end tell
end tell
end tell
I don't really know how to work InDesign — I have an old copy of it, but it would be nice if you provided an example document that I could download and test — but just in terms of AppleScript you probably want to do something like so:
tell application "Adobe InDesign"
repeat with this_page in pages
tell this_page
set text_frames_list to (text frames whose name of applied object style is "PriceBox" and contents contains "/$")
repeat with a_text_frame in text_frames_list
tell a_text_frame
set applied paragraph style of paragraphs of a_text_frame to "2forPrice"
end tell
end repeat
end tell
end repeat
end tell
The following script, when run in AppleScript Editor returns as text the autoshape type of the objects on the page. However, when run from the applescript menu from within PowerPoint, it returns a script constant instead.
I'm using a more complicated version of this to send properties of the objects to different applications based on what auto shape type it is... tables go one place, placeholders another, and rectangles et al to third. I'm also launching this from within PPT to push out the data, and can't really pull it from any of the other apps, so the AppleScript menu would be where I want it to be.
Can anyone tell me why the same script gives two results?
Thanks,
Alex
tell application "Microsoft PowerPoint"
set currentSlideNumber to slide index of slide range of selection of document window 1
set theSlide to slide currentSlideNumber of active presentation
end tell
getProperty(theSlide)
to getProperty(theSlide)
tell application "Microsoft PowerPoint"
repeat with thisShape in (get every shape of theSlide)
set shapeType to shape type of thisShape
set shapeContent to content of text range of text frame of thisShape
display alert (shapeType as string)
end repeat
end tell
end getProperty
Converting constants (or application properties which standard applescript doesn't understand) to text is tricky. My guess is that when in the powerpoint menu the script understands the constant better and thus you see that.
In any case, I had the same issue with Finder constants and decided to handle the conversion to text myself with an if statement. It's a cumbersome solution because you have to account for every constant but at least you know it will happen properly.
Here's an example. Suppose there is a shape constant of "rect" which stands for a rectangle, and "circ" standing for circle.
NOTE: you can probably use the name of the actual property instead of the constant in the code.
to getProperty(theSlide)
tell application "Microsoft PowerPoint"
repeat with thisShape in (get every shape of theSlide)
set shapeType to shape type of thisShape
if shapeType is <<rect>> then
set shapeTypeText to "rectangle"
else if shapeType is <<circ>> then
set shapeTypeText to "circle"
end if
set shapeContent to content of text range of text frame of thisShape
display alert (shapeTypeText)
end repeat
end tell
end getProperty
I'm trying to change a colour in an illustrator document from one color the another heres what i've got but it keeps saying "can't find color" i'm not sure what i'm doing wrong?
tell application "Adobe Illustrator"
if exists color is equal to "C=0 M=0 Y=0 K=90" then
set color to "C=0 M=0 Y=0 K=100"
end if
end tell
tell application "Adobe Illustrator"
set allMyItems to every path item of current document whose fill color is {cyan:0.0, magenta:0.0, yellow:0.0, black:90.0}
repeat with myItem in allMyItems
set fill color of myItem to {cyan:0.0, magenta:0.0, yellow:0.0, black:100.0}
end repeat
end tell
Looks like it cant understand what exactly color are you setting (i.e. fill color, stroke color, etc.). Or if you just setting a variable named 'color' than you probably need to choose another name (something like myColor) because this one is reserved