AppleScript Application¶
-
Create a New Script
- Open the Script Editor.
- Create a new document.
-
Paste the following AppleScript code into the Script Editor
w1080p Code (click to view)
AppleScript 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
on open droppedFiles set targetWidth to 800 -- Target width for resizing (in pixels) repeat with eachFile in droppedFiles -- Get the file path set filePath to POSIX path of eachFile -- Check file extension and process only image files if filePath ends with ".jpg" or filePath ends with ".jpeg" or filePath ends with ".png" then -- Determine the output path (add _resized to the original filename) set outputFilePath to (text 1 through -5 of filePath) & "_w1080.jpg" -- Check if output file already exists set fileExists to false try set fileExists to (do shell script "test -e " & quoted form of outputFilePath & " && echo true || echo false") is "true" end try -- If the file exists, ask the user if they want to cancel if fileExists then set cancelChoice to display dialog "File already exists. Do you want to cancel?" buttons {"Cancel"} default button "Cancel" if button returned of cancelChoice is "Cancel" then return -- Skip this file without showing a message end if end if -- Resize the image using ffmpeg do shell script "/opt/homebrew/bin/ffmpeg -i " & quoted form of filePath & " -vf \"scale=1080:-1\" -q:v 2 " & quoted form of outputFilePath else display dialog "Only image files (JPG, PNG, etc.) are allowed." buttons {"OK"} default button "OK" end if end repeat -- Display a completion message -- display dialog "Images resized successfully!" end openNote
Line28: replace “/opt/homebrew/bin/ffmpeg” with the path to ffmpeg on your pc
Terminal% which ffmpeg /opt/homebrew/bin/ffmpeg -
Save as an Application
- From the Script Editor menu, choose File > Save As.
- When saving, select the following settings:
File Format: Application
Location: Choose where you want to save (e.g., Desktop).
-
After saving, this AppleScript will work as an application.
Drug and dorp a jpg or png file
Note
If you don’t have ffmpeg, install it.
% brew install ffmpeg
% brew --version
Homebrew 4.0.6
The resized images to be saved to ~/Desktop/resized_output folder¶
w1080p Code (click to view)
| AppleScript | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
The resized video_1080p.mp4 to be saved to ~/Desktop/resized_output folder¶
video_1080p Code (click to view)
| AppleScript | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |