Skip to content

AppleScript Application

  1. Create a New Script

    1. Open the Script Editor.
    2. Create a new document.
  2. 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 open 
    

    Note

    Line28: replace “/opt/homebrew/bin/ffmpeg” with the path to ffmpeg on your pc

    Terminal
    % which ffmpeg
    /opt/homebrew/bin/ffmpeg
    
  3. Save as an Application

    1. From the Script Editor menu, choose File > Save As.
    2. When saving, select the following settings:
      File Format: Application
      Location: Choose where you want to save (e.g., Desktop). alt text
  4. 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
To install ffmpge, you need Homebrew installed
% brew --version
Homebrew 4.0.6
If you do not have Homebrew, install it from Homebrew

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
on open droppedFiles
    repeat with eachFile in droppedFiles
        -- Get the file path
        set filePath to POSIX path of eachFile

        -- Set output directory on Desktop
        set outputDir to POSIX path of (path to desktop) & "resized_output"

        -- Create output directory if it doesn't exist
        do shell script "mkdir -p " & quoted form of outputDir

        -- Check file extension
        if filePath ends with ".jpg" or filePath ends with ".jpeg" or filePath ends with ".png" then

            -- Get filename without extension
            set baseName to do shell script "basename " & quoted form of filePath & " | sed 's/\\.[^.]*$//'"

            -- Set output file path
            set outputFilePath to outputDir & "/" & baseName & "_w1080.jpg"

            -- Check if output file 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 fileExists then
                set cancelChoice to display dialog "File already exists in resized_output. Cancel?" buttons {"Cancel"} default button "Cancel"
                if button returned of cancelChoice is "Cancel" then
                    return
                end if
            end if

            -- Resize 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) are allowed." buttons {"OK"} default button "OK"
        end if
    end repeat
end open

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
on open droppedFiles
    -- Output directory on Desktop
    set outputDir to POSIX path of (path to desktop) & "resized_output"
    do shell script "mkdir -p " & quoted form of outputDir

    repeat with eachFile in droppedFiles
        set filePath to POSIX path of eachFile

        -- Check extension (mov or mp4)
        if filePath ends with ".mov" or filePath ends with ".mp4" then

            -- Fixed output filename
            set baseName to "output_1080p"
            set outputFilePath to outputDir & "/" & baseName & ".mp4"

            -- Add serial number if file exists
            set counter to 1
            repeat while (do shell script "test -e " & quoted form of outputFilePath & " && echo yes || echo no") is "yes"
                set outputFilePath to outputDir & "/" & baseName & "_" & counter & ".mp4"
                set counter to counter + 1
            end repeat

            -- ffmpeg conversion
            do shell script "/opt/homebrew/bin/ffmpeg -i " & quoted form of filePath & ¬
                " -vcodec libx264 -crf 25 -preset medium -vf scale=-2:1080" & ¬
                " -map 0:v:0 -map 0:a? -acodec libmp3lame -q:a 4 -ar 48000 -ac 2 " & ¬
                quoted form of outputFilePath

        else
            display dialog "Only MOV or MP4 files are allowed." buttons {"OK"} default button "OK"
        end if
    end repeat
end open