Executing Shell Scripts from the OS X Dock?

前端 未结 9 1694
自闭症患者
自闭症患者 2020-12-22 17:15

How do I set up a shell script to execute from the Mac OSX dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set som

9条回答
  •  礼貌的吻别
    2020-12-22 18:00

    As joe mentioned, creating the shell script and then creating an applescript script to call the shell script, will accomplish this, and is quite handy.

    Shell Script

    1. Create your shell script in your favorite text editor, for example:

      mono "/Volumes/Media/~Users/me/Software/keepass/keepass.exe"

      (this runs the w32 executable, using the mono framework)

    2. Save shell script, for my example "StartKeepass.sh"

    Apple Script

    1. Open AppleScript Editor, and call the shell script

      do shell script "sh /Volumes/Media/~Users/me/Software/StartKeepass.sh" user name "" password "" with administrator privileges

      • do shell script - applescript command to call external shell commands
      • "sh ...." - this is your shell script (full path) created in step one (you can also run direct commands, I could omit the shell script and just run my mono command here)
      • user name - declares to applescript you want to run the command as a specific user
      • " - replace with your username (keeping quotes) ex "josh"
      • password - declares to applescript your password
      • "" - replace with your password (keeping quotes) ex "mypass"
      • with administrative privileges - declares you want to run as an admin

    Create Your .APP

    1. save your applescript as filename.scpt, in my case RunKeepass.scpt

    2. save as... your applescript and change the file format to application, resulting in RunKeepass.app in my case

    3. Copy your app file to your apps folder

提交回复
热议问题