Jump to content

Resize Image

Recommended Posts

For anybody who wants the image file to save as a new file rather than replace the original:

  1. Open the "Process image(s)" AppleScript block in the workflow
  2. Find this line in the script:
  3. save this_image in myPath

    And insert the following to append the image filename with the target width (e.g. image.png becomes image-300.png when resized to 300px width):

    				-- append target width to file name
    				set oldDelim to AppleScript's text item delimiters
    				set AppleScript's text item delimiters to {"."}
    				set theExt to last text item of myPath
    				set AppleScript's text item delimiters to {"." & theExt}
    				set file_path_list to every text item of myPath
    				set AppleScript's text item delimiters to {"-" & target_width & "." & theExt}
    				set myPath to the file_path_list as string
    				set AppleScript's text item delimiters to oldDelim




Link to post
  • 8 months later...

I needed a workflow that put the resized images into a sub folder of the originals, so made the following amendments.

It can handle multiple file selections within differing directories and place the resize-x folder within the respective directory relative to the original image.

  1. Open the "Process image(s)" AppleScript block in the workflow
  2. Find the following lines in the downloadable version (Lines 27-28)
    			set myPath to this_file
    		end if

    And insert the following after it that will create a new directory next to the file being resized in the format of 'resize-{resize-width}' (resize-500, resize-1024 for example)

            -- Remove the file name from the end of the path string
            set filePath to characters 1 thru -((offset of "/" in (reverse of items of myPath as string)) + 1) of myPath as text
            set fileName to name of (info for myPath)
            -- Create a full path to the folder that we want.
            set resizeFolderName to ((filePath as text) & "/resize-" & (target_width as text) & "/") as text
            -- Check for the resize-x folder and create it if not present
            if folderExists(resizeFolderName) then
    			set outputFolder to resizeFolderName
    			set createThisFolder to POSIX file filePath as alias
                tell application "Finder" to make new folder in createThisFolder with properties {name:"resize-" & target_width}
    			set outputFolder to resizeFolderName
            end if


  3. Change the following line (Originally on line 38, with the addition of the above, its now on line 60)

    save this_image in myPath


    save this_image in outputFolder & fileName


  4. Add the following function to the end of the file:

    on folderExists(theFolder)
        tell application "Finder"
                set thisFolder to the POSIX path of theFolder
                set thisFolder to (POSIX file thisFolder) as text
                -- set thisFolder to theFolder as alias
                return true
            on error err
                return false
            end try
        end tell
    end folderExists


Or, if you want the whole script in one thing, its on a Gist here: https://gist.github.com/danstreeter/23fe01074034832fec09c0b633522559

Edited by MrStreeter
Correct Gist link
Link to post
  • 1 year later...
  • 2 months later...
On 11/7/2019 at 11:59 AM, naymapl said:

Hi - this workflow working perfect with macos 10.14 but stop working on Catalina 10.15. I got always error ( can't get item 1 of {} )- anybody have any idea what is wrong ? Thnaks for any sugestions.


I get the same issue. Any suggestions?

Link to post

Seems to be an issue with Image Events under Catalina: https://forums.developer.apple.com/thread/124420

To fix there is a simple solution: https://darjeelingsteve.com/articles/Fixing-"Image-Events"-AppleScripts-Broken-in-macOS-10.15-Catalina.html



These problems appear to be caused by Image Events not having Full Disk Access permissions. Fortunately it's an easy fix.


First, launch System Preferences and navigate to the Security and Privacy pane. Click the Privacy tab, scroll down the menu on the left, and click on Full Disk Access. Click the + icon in the right hand box, and navigate to System > Library > Core Services. Select Image Events, and click the Open button.


Link to post
  • 7 months later...
On 1/11/2020 at 10:25 AM, Acidham said:

Great! Thank you very much! Works! 👍

This should be added to the description of the workflow to make it work!

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...