Using applescript to change stroke weights conditionally in Illustrator CS6 - applescript

I was trying to use this code.
tell application "Adobe Illustrator"
tell front document
set properties of every path item whose stroke weight is less than 0.2 to {stroke width:0.2}
end tell
end tell
I see no reason why it shouldn't work, but it gets hung up on the phrase "path item." I don't understand what else I should do! I'm trying to get this to work in Illustrator CS6.

Full disclosure: I'm doing this on CS4, but it really should be the same, although I suppose it is possible (unlikely) that "stroke width" changed to "stroke weight". I think you also need to specify the layer. Try something like (of course you'll have to specify the correct layer) this; it works for me:
tell application "Adobe Illustrator"
tell front document
set stroke width of (every path item of layer 1 of it whose stroke width is less than 0.2) to 0.2
end tell
end tell

Related

Change the text's font in current layer in Photoshop using AppleScript

I want to change the text's font in current layer in Photoshop using AppleScript, but I am new to AppleScript. By looking up the Photoshop's script dictionary, I know how to reach to the current layer so far:
tell application "Adobe Photoshop CC 2018"
tell current document
tell current layer
... <= What should I do next?
end tell
end tell
end tell
But I don't have clue what to do next, I can't find related properties in the dictionary to continue to reach the text in the layer. Could somebody shed some light on this? Thanks!
Finally I figured out the solution:
tell application "Adobe Photoshop CC 2018"
tell current document
tell current layer
if kind is text layer then
set font of text object to "<font-name>"
end if
end tell
end tell
end tell

Applescript to make the next tab the current document in Photoshop

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

AppleScript and InDesign CS6: minimum document size error?

Let's do an experiment. Using InDesign CS6, make a new document that is 1" x 1". No problem here, right?
Now run this script:
tell application "Adobe InDesign CS6"
set page width of document preferences of active document to 1
end tell
Should be easy, right? You're just telling InDesign to set the document size to a size it already has.
error "Adobe InDesign CS6 got an error: Data is out of range." number 30481
Just what in the blazes is going on here? I'm able to get applescript to set the page size down to 1.0139 inches -- but no smaller. Anyone have an idea?

PowerPoint Applescript Menu giving different result than AppleScript Editor

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

Applescript to change illustrator colors

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

Resources