I am able to replace the name of every layer of the current document, but when I pass it "where name ends with" it fails & the exception does not give any valuable feedback.
tell application "Adobe Photoshop CS3"
tell current document
set name of every layer where name ends with "copy*" to "replace_using_sed"
end tell
end tell
Can you spot the error or perhaps you know an alternative way about this?
The copy* is causing the error. You can't use * as wildcard in AppleScript. Instead, use ... where name contains "copy" ....
Here's my working version of your script (tested with Photoshop CS5):
tell application "Adobe Photoshop CS3"
set layerList to name of every layer in current document where name contains "copy"
end tell
repeat with currentName in layerList
set layerName to text 1 thru ((offset of "copy" in currentName) - 1) of currentName
tell application "Adobe Photoshop CS3"
set (the name of first layer in current document where name contains "copy") to layerName
end tell
end repeat
Not sure if this will fix the whole script, but it's called a "whose" filter... so replace the word "where" with "whose". I'm not saying a whose filter works with photoshop, but you can try. If it doesn't work then you have to get all of the layers, loop through them with a repeat loop, and filter each name one-by-one.
Related
I have a document with over 1000 images (set a), each of which are sitting on separate folder and I am loading them into my word document by entering the path in a "field". The images get uploaded to the word document and displayed.
I have another 1000 images (set b), all of which are named in the exact same way, except that they all end a different letter (b instead of a). I have tried to take my pre-existing and working word document that displayed the first 1000 images (set a), and edit the path in the field so that they all reference the set b images. This change is easy to make as I just need to find and replace everywhere that the text image_a.pngappears with image_b.png.
However, when I do this, the images don't actually refresh and are instead still displaying all of the images from set a. I have played around with a lot of stuff like saving the document as and opening it again, and for a separate issue I had to enter and exit print preview for my number sequence to update, and I tried that for this issue, but that still doesn't help. The only thing that I have found that works is if I go to each field individually, right click on it and select "edit field" and then select ok, and then the correct image will be displayed. However this is not a practical solution because I would have to do this over 1000 times. Does anyone know what is going on here and does anyone know a way to refresh/update all of the 1000 images at once?
Thanks!
Try Ctrl+A followed by the F9 key. You may need to press an Fn key with the F9.
If you need something more nuanced, I can provide a macro. For that, I would need the name of the field being used.
You may want to look at Paul Edstein's tutorial on relative paths in fields.
In NetLogo is there a way to treat a text string as a command and execute it?
In the simplest case - is there way to simply generate a text string like "forward " concatenated with a number I don't know till runtime, so i end up with a text variable equal to "forward 8", say, and then execute that command?
My immediate need is probably what LOGO did, namely, have the user click buttons to move a turtle around with the pen down to draw some shape, say a square, saving those commands as they are written to an output window, saving the full text of the output window to some named text like "draw-square", and then have the user able to type "draw-square" in the command center and have the turtle execute those steps and draw a new square.
I could work around this I suppose by exporting the output to a myfile.nls text file, then restarting NetLogo to bring in the new command file using the __includes [ "myfile.nls"] step , but I'd rather not ask them to do that if I can avoid it and in any case that wouldn't work over the web.
Jasper answered the question in the comment above -- "run" and "runresult" do what I wanted.
I'm using a Mac and I'm preparing accounts for a company. Every payslip which I've made in Microsoft Word has a voucher number. Because a transaction was missed all voucher numbers are wrong so now there are hundreds of wrong payslips. I want to create a script that can find the following GREP (find beginning of paragraph, text:Vch, any character until \r):
^Vch.+\r
and replace it with nothing (thereby deleting the whole sentence).
I was thinking of using Applescript as it can open the document, perform the GREP find (tricky part), save the document and save it as a pdf (all which is needed).
But apparently my knowledge fails me. Commands from the dictionary like create range, execute find, all bring errors.
Somebody experienced in Applescript that could help me devise a script? Any suggestions? It should be something like:
Tell application "Microsoft Word"
tell active document
set myRange to create range start 0 end 0
tell myRange
execute find find "^Vch.+\r" replace with ""
end tell
end tell
end tell
Many thanks!
There are no special characters to indicate the beginning of a line.
To search at beginning of the paragraph, the script must use return & "some text"
You can use "^p" as paragraph mark, but it doesn't work when you set the match wildcards property to true
To match an entire paragraph, the script must use return & "some text" & return, and the script must use replace with return to delete one paragraph mark instead of two.
Because the first paragraph does not begin with a paragraph mark, the script must use two execute find commands.
The wildcard is *
tell application "Microsoft Word" -- (tested on version 15.25, Microsoft Office 2016)
-- check the first paragraph
select (characters of paragraph 1 of active document)
execute find (find object of selection) find text ("Vch*" & return) replace with "" replace replace one wrap find find stop with match wildcards and match case without match forward and find format
--to search forward toward the end of the document.
execute find (find object of selection) find text (return & "Vch*" & return) replace with return replace replace all wrap find find continue with match wildcards, match case and match forward without find format
save active document
-- export to PDF in the same directory as the active document
set pdfPath to path of active document & ":" & (get name of active window) & ".pdf"
set pdfPath to my createFile(pdfPath) -- create an empty file if not exists, the handler return a path of type alias (to avoid grant access issue)
save as active document file name pdfPath file format format PDF
end tell
on createFile(f)
do shell script "touch " & quoted form of POSIX path of f
return f as alias
end createFile
I'm trying to add a hyperlink object inside a Word comment.
To create a new comment in the active document I'm using this piece of script:
tell application "Microsoft Word"
set tempString to "lorem ipsum"
make new Word comment at selection with properties {comment text:tempString}
end tell
but now I'm not able to get a reference to the new created comment for use it with the command "make new hyperlink object".
Thanks for any suggestions.
Riccardo
I don't think you can work with the object returned by make new Word comment (at least not in this case), and you have to insert a unique, findable string then iterate through the comments:
tell application "Microsoft Word"
-- insert a unique string
set tempString to (ASCII character 127)
set theComments to the Word comments of the active document
repeat with theComment in theComments
if the content of the comment text of theComment = tempString then
set theRange to the comment text of theComment
-- you do not have to "set theHyperlink". "make new" is enough
set theHyperlink to make new hyperlink object at theRange with properties {text range:theRange, hyperlink address:"http://www.google.com", text to display:"HERE", screen tip:"click to search Google"}
insert text "You can search the web " at theRange
exit repeat
end if
end repeat
end tell
(edited to insert some text before the Hyperlink. If you want to insert text after the hyperlink, you can also use 'insert text "the text" at end of theRange.).
So for adding text, it was enough to use "the obvious" after all.
[
For anyone else finding this Answer. The basic problem with working with Word ranges in Applescript is that every attempt to redefine a range in the Comments story results in a range that is in the main document story. OK, I may not have tried every possible method, but e.g., collapsing the range, moving the start of range and so on cause that problem. In the past, I have noticed that with other story ranges as well, but have not investigated as far as this.
Also, I suspect that the reason why you cannot set a range to the Word comment that you just created is because the properties of the Comment specify a range object of some kind that I think is a temporary object that may be destroyed immediately after creation. SO trying to reference the object that you just created just doesn't work.
This part of the Answer is modified...
Finally, the only other way I found to populate a Comment with "rich content" was to insert the content in a document at a known place, then copy its formatted text to the comment, e.g. if the "known place is the selection, you can set the content of theComment via
set the formatted text of the comment text of theComment to the formatted text of the text object of the selection
If you are using a version of Word that supports VBA as well as Applescript, I don't really see any technical reason why you shouldn't invoke VBA to do some of these trickier things, even if you need the main code to be Applescript.
]
Finally I got a solution here:
https://discussions.apple.com/message/24628799#24628799
that allowed me to insert the hyperlink in reference with part of the comment text, with the following lines, if somebody in the future will search for the same:
tell application "Microsoft Word"
set wc to make new Word comment at end of document 1 with properties {comment text:"some text"}
set ct to comment text of wc
set lastChar to last character of ct
make new hyperlink object at end of document 1 with properties {hyperlink address:"http://www.example.com", text object:lastChar}
end tell
I am going nuts here. I have tried countless permutations/variations of "save as active document file format PDF" but none seem to work. I get AppleScript errors with all of them.
So can anyone tell me:
What is the exact syntax to save the active document as a PDF file in AppleScript, using Word?
It seems that there is no coherence whatsoever in the Office for Mac scripting, as I have this working for Excel and PowerPoint and even there the syntax is different:
excel
save active workbook in 'MyFile.pdf' as PDF file format
PowerPoint
save active presentation in 'MyFile.pdf' as save as PDF
What is the correct syntax for Word?
Thanks!
It seems I found it after all:
set myDoc to "/Users/X/Desktop/test.docx"
set pdfSavePath to "Users:X:Desktop:test.pdf"
tell application "Microsoft Word"
activate
open myDoc
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name pdfSavePath
end tell
I am no AppleScript expert. I had slashes instead of : as path separators. With : it works
Joris Mans script is pretty nice, but has a flaw. It does not ensure that Word has an active document ready (set theActiveDoc to the active document might return missing value)
I also improved the script to use the Finder selection as input, placing the PDFs into the same place as the word files. I did not test the file types, but word will complain about that.
tell application "Finder"
set input to selection
end tell
tell application id "com.microsoft.Word"
activate
repeat with aFile in input
open aFile
set theOutputPath to ((aFile as text) & ".pdf")
repeat while not (active document is not missing value)
delay 0.5
end repeat
set activeDoc to active document
save as activeDoc file name theOutputPath file format format PDF
close active document saving no
end repeat
end tell