Apple - How do I make a bash script so that I can drag its input on top of the icon?

You should be able to turn your script into an application with Automator - Applications -> Utilities -> Automator.app. Look for an option called "Run Shell Script" and once you're done, it should behave like other apps in that anything that is dragged and dropped on it will be run with it. Good luck!


I have created a AppleScript, that redirects all files dropped onto it, to a shell script with the matching name. Simply save as application from within Apple's ScriptEditor and rename as script.app to match your script.sh

on getScriptName()
    tell application "Finder"
        set p to path to me -- alias to the file of the running script
        set fullName to name of file p as text
        set strippedName to text 1 thru ((fullName's length) - (offset of "." in ¬
            (the reverse of every character of fullName) as text)) of fullName -- strip off extension
    end tell
    set my_path to (((path to me as text) & "::") as alias) as string -- parent folder of running script
    set ScriptName to POSIX path of my_path & strippedName & ".sh" -- path to bash script, expected to reside here
    return ScriptName
end getScriptName

on run -- double click on application
    set scriptfile to getScriptName()
    tell application "Terminal"
        activate
        do script scriptfile
    end tell
end run
on open dropfiles -- drag 'n drop files onto application
    set posixfiles to " "
    repeat with dropfile in dropfiles
        set posixfiles to posixfiles & " " & POSIX path of dropfile
    end repeat
    set scriptfile to getScriptName()
    tell application "Terminal"
        activate
        do script scriptfile & " " & posixfiles
    end tell
end open

It's based on this answer, I only got rid of hard-wired script.sh filename