Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Change file path of embedded pictures

I'm sort of a beginner with Applescript, but I created an application in it that takes screenshots of different web pages and saves them in my Pictures folder. I have a proposal template in a Word document that has these pictures linked and embedded into it. Whenever I want to create a new proposal, I run the application and get the specified images I need, and update the links in the Word doc so that the new images display. I then break the links and save the doc as something else.


Anyway, I have a colleague who would like to use this application. The files in the Word doc are linked to Macintosh HD/users/Me/Pictures. How can my colleague easily set all the images in the Word doc to their own file path, ie Macintosh HD/users/MyColleague/Pictures?


Something like


tell application "Microsoft Word"

set the path of active picture to "Macintosh HD:Users:MyColleague:04-ReportMenu.jpg"

end tell


Multiple salespeople will eventually be using this script. If I could add a function into my Applescript app so that whenever the proposal template is opened, the path to the images is changed to that users's picture folder, that would be amazing. Other solutions are welcomed.

Posted on Jan 29, 2014 2:18 PM

Reply
10 replies

Jan 29, 2014 3:41 PM in response to rjvmurphy

If your example - and sorry I don't have Word to try it - shows how you set the link in the first place, you can use:


set the path of active picture to (path to home folder as string) & "04-ReportMenu.jpg"


However, you say further down that the reference should be to the user's picture folder. Just substitute "path to pictures folder" in the above line.


If I've misunderstood your question, please post back!

Jan 29, 2014 3:47 PM in response to Arkouda

Thanks! I apprecaite the response, but unfortunately, the way I added the pictures originally was just by embedding them in Word, not via Applescript. I don't really want the app to make any changes to the document (ie, picture placement). The command I provided was what I thought the ideal solution would be, but it doesn't actually work. In fact there is no "active picture" identifier. Sorry I wasn't more clear about that part!

Jan 29, 2014 4:50 PM in response to twtwtw

Sure, thanks for the reply. My organization created a sales proposal generator in Word. It creates a sales proposal based on some user inputs. Embedded in the proposals are demonstrations of our product in the form of screenshots of our product from our website. One of our designers updates the standard images with customized branded images for the client we are pitching. It's very time consuming to get these new branded images from the web, crop them and swap them out in the Word proposal, so I created an app that will do it. The app visits a list of pages, takes a screenshot of the Safari window and pastes a named image in my Pictures folder. I embedded the images in the Word doc so that they link to my Pictures folder. All I have to do is update the links and I have a new branded proposal. It works great on my own machine, but if I share it, the path obviously breaks and the Word image update doesn't work.


Here's a snippet of my code. The following takes a screenshot of our site and saves it in Pictures:


-- Report Screenshot


delay 1

tell application "Safari" to set the bounds of the front window to {0, 20, 915, 935}

delay 0.1

tell application "Safari"

tell window 1 to set URL of current tab to "https://website.com/demox?rm=report"

delay 4

end tell

do shell script "screencapture -o -l$(osascript -e 'tell app \"Safari\" to id of window 1') ~/Pictures/05-Report.jpg"

end tell


The links in Word update to the brand-specific images I just grabbed once I select Edit -> Links -> Update Now

User uploaded file

I need a quick way, in Applescript, to update /Users/me/Pictures/photo.jpg to Users/MyColleague/Pictures.jpg in Word. Does this help at all??

Jan 29, 2014 7:17 PM in response to rjvmurphy

The trick to this is using the path to command of the standard additions osax. If you need POSIX paths, something like the following will work generically across different machines:


set picPath to POSIX path of (path to pictures folder from user domain) & "05-Report.jpg"


If you have trouble adjusting it to your needs let me know.

Jan 30, 2014 9:09 AM in response to twtwtw

Thanks twtwtw. I amended it to:


-- Report Screenshot

set picPath to POSIX path of (path to pictures folder from user domain) & "05-Report.jpg"

delay 1

tell application "Safari" to set the bounds of the front window to {0, 20, 915, 935}

delay 0.1

tell application "Safari"

tell window 1 to set URL of current tab to "https://website.com/demox?rm=report"

delay 4

end tell

do shell script "screencapture -o -l$(osascript -e 'tell app \"Safari\" to id of window 1') " & picPath



The underlined parts are what I changed. This saves the file directly into my users folder, though, and sets the file name to "Pictures05-Report.jpg"

Also, do you have any ideas on how I would tell Word to set the picPath to all of the embedded pictures in a document?

Jan 30, 2014 2:22 PM in response to rjvmurphy

You haven't given enough information for me to give you a complete answer, or in fact even for me to be sure I'm aswering the right question. But in principle, if we assume that the link in question is the first link on the first Word document, this code will change the file it points to:


set picPath to POSIX path of (path to pictures folder from user domain) & "05-Report.jpg"

tell application id "com.microsoft.Word"

tell document 1

set hyperlink address of first hyperlink object to picPath

end tell

end tell


There are a host of nuances that could make life easier (for instance, you could locate the proper hyperlink easily by its name or displayed text, if you know what those are), but it's too vague to work with as given.

Change file path of embedded pictures

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.