How to open files directly on Photoshop from a text box Mac Application

后端 未结 1 1017
暗喜
暗喜 2020-12-22 13:27

Hello dear programming community. Hope everyone is staying safe.

I have thousands of image files in hundreds of directories and finding them can take time.

1条回答
  •  萌比男神i
    2020-12-22 13:36

    You can do this with Automator and a little bash script. Start Automator, and create a new application. Then click Utilities (annotated yellow) and then drag Run Shell Script (annotated magenta) to the right side (annotated cyan) and drop.

    Now paste the following code into the right side:

    # You can edit these parameters to suit your local situaton
    LOCATION="/Users/mark/Photos"
    PHOTOSHOP="Adobe Photoshop CC 2019"
    
    # Pop up a dialog asking for filenames
    list=$(osascript -e 'Tell application "System Events" to display dialog "Enter filenames to Photoshop - separate with commas:" default answer ""' -e 'text returned of result' 2>/dev/null)
    
    # Make array of filenames from list, splitting on commas
    IFS=',' read -ra fnames <<< "$list"
    
    # Generate full paths of each filename, in another array
    fullpaths=()
    for f in "${fnames[@]}"; do
         # Try to find file, ignoring case, in specified location
        full=$(find "$LOCATION" -iname "$f" -print 2> /dev/null)
        # Add to list to pass to Photoshop if found
        [ ! -z "$full" ] && fullpaths+=("$full")
    done
    
    # Start Photoshop with the specified files
    open -a "$PHOTOSHOP" "${fullpaths[@]}"
    

    Now save the application on your Desktop, I called mine FindAndShop. You can then double-click it to run it. That is all you need to answer your question. The following is just prettification!

    Here it is in action:


    If you want to, you can change the icon, so I made a new, square icon in Photoshop and copied the image, then I right-clicked my shiny new app, and chose Get Info. Now click the cyan area, then on the menu bar at the top of the screen, click Edit then Paste:

    Now the app looks like this on my Desktop:

    0 讨论(0)
提交回复
热议问题