APPLESCRIPT search in excel, find in a folder, manage in photoshop

Hi everyone,

Sorry if my problem is trivial, but I am a complete beginner in scripting, I have tried to find a solution on the web yet without any result.


I have an excel file with a colum filled with values. Each cell of the column contains value that is a name of a file (they are images).

For each name I need to search it on my mac and open it in photoshop and give an action that I have already set.

Then do it again for each value of the excel file.


As I am a totally beginner, I am doing it by little steps, but I am stuck at the "searching-part" within finder.

Can anyone help me please?

thanks





iMac 21.5″, macOS 10.14

Posted on Nov 16, 2021 5:08 AM

Reply

Similar questions

5 replies

Nov 16, 2021 9:56 AM in response to enplein

At a high level, your ask is entirely possible, but here are a lot of gaps in the details that will make a huge difference in execution:


> I have an excel file with a colum filled with values


Does it have to be in Excel? If it's just a column on values that are easily identifiable then it's not too bad, but Excel is notorious for having a terrible AppleScript implementation and it not the place I'd look to start learning AppleScript.

The script would be much simpler if it can just read a list of file names from a text file on disk.

For now I'll focus on Excel (since it's just one column), but it's worth considering.


> For each name I need to search it on my mac


Search where? A specific directory, or anywhere on the disk? that's a heavy lift, searching through multiple thousands of files looking for a match. Also what happens if there are multiple matching filenames? which one(s) do you use?

If it's files within a single directory, it's pretty simple. It isn't clear what your use case is.


> open it in photoshop and give an action that I have already set.


Opening it in Photoshop is trivial. Off-hand I don't know how to execute an action via AppleScript.


> Then do it again for each value of the excel file.


Looping is easy, but presumably the script needs to save and close the file before moving on (unless the action already does that). Otherwise you'll end up with many, many Photoshop documents open, bogging down your system.


The hard part here may be detecting when the action is completed. You don't want the script to kick off the next file while the previous one is still processing. There are ways to deal with this, but it's a detail that cannot be overlooked.

Nov 22, 2021 1:30 PM in response to enplein

> There could be more than one image saved with the same name, so I thought the script has to open the one saved most recently.


That's not how it works - at least not automatically.


When you identify a file you need to be specific - usually by providing a path or a directory the file should be in. If you look for all instances of a given file name on disk the order returned is undefined - there is nothing to say you'll get the oldest/newest/smallest/largest/deepest/whatever file. It is up to you to determine which file to use. knowing that you want the newest file helps.


However, bear in mind that trawling the entire disk (tens of thousands of files) for each iteration of the loop is going to be excruciatingly slow. You'll be far better off if you can restrict the search to a specific directory tree.


Assuming there's a solution to the above, the other issue is going to be polling Photoshop to determine when the action is complete - that likely involves a loop checking the front window, waiting for it to fail (because the window has been closed. Not hard to do.

Nov 16, 2021 6:49 AM in response to enplein

When you are interacting with applications using AppleScript, you must conform to the current AppleScript dictionary support for those applications that provide it. And, that scripting support can and does change between releases of the vendor software, so it is a moving target for support. It turns out that Excel and Photoshop have AppleScript support in Apple's Script Editor > File menu > Open Dictionary… when they are installed.


However, anyone helping you with the scripting code to do what you want, if actually supported by the respective scripting dictionaries, would need to have the same version of Excel and Photoshop that you are using in order to TEST the code for functionality. I have neither application and what you have asked is non-trivial, especially the Photoshop aspect of it.

Nov 16, 2021 8:03 AM in response to VikingOSX

Hi VikingOSX,

thanks for your reply. Actually, I thought to solve the photoshop part by triggering the action with keystroke, so I think it won't be a problem.

As for the Excel part I may have already found a way to do it (though I need to study more how to loop it).

What I am struggling with is how to say to finder to search the file, find and open it in photoshop, that I think it doesn't depend by different versions of the softwares.


thanks

Nov 17, 2021 2:26 AM in response to Camelot

Hi Camelot,

I'll try to explain better.

my original file is in excel, but I could save it as number's file, that would be fine as well.


The excel file is a simple list of hundred of names of images saved in one of my archives that is in an external drive. So I could narrow the research to the main folder where images are saved.


There could be more than one image saved with the same name, so I thought the script has to open the one saved most recently.


The action in photoshop automaticly saves and close the file, so I think it won't be a problem. As I have given a shortcut to trigger it, I think I could use a keystroke.


Hope it' helpful

thanks





This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

APPLESCRIPT search in excel, find in a folder, manage in photoshop

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