AppleScript with Bash Variables

Discussion in 'Mac Programming' started by gpchess2k, Apr 6, 2017.

  1. gpchess2k macrumors newbie


    Oct 12, 2015

    Looking for help on setting up a variable properly within a bash script. My goal is to install a printer driver by calling the lpadmin command from within an AppleScript (.app). I am trying to point the variable '$dir' to the same location as the script. I placed the name of the driver at the end of the variable command since I cant seem to figure out the syntax. Here is what I got so far:

    dir=(cd -P -- "$(dirname -- "$0")" && pwd -P ) CNMCIRAC5250S2.ppd.gz
    lpadmin -p $SysPrinter1 -v $Addr1 -D $DispPrinter1 -L $Bldg1 -m $dir -E -o printer-is-shared=false
  2. superscape macrumors 6502a


    Feb 12, 2008
    East Riding of Yorkshire, UK

    I don't quite understand. Can you show me how you're using it in your AppleScript?
  3. psingh01 macrumors 65816

    Apr 19, 2004
    I don't have a lot of experience with AppleScript but it sounds like you are trying to do something similar to what I did for a small Automator utility I wrote.

    In my case I happen to have a java cli program that I wanted to run with an input file chosen by the user and I wanted this to work as a simple drag and drop utility.

    I had the java jar embedded within the .app folder. In my Automator program I had two steps. An AppleScript step and a bash script step. The output of the AppleScript step is sort of piped into as input to the bash script step.

    I used the POSIX path to get the unix style paths of an input file that the user dragged and dropped onto my utility. I also get the "path to me" to which is the path to automator utility. I use this as reference to then call my embedded jar file in the bash step.

    Run Apple Script step
    on run {input, parameters}
        set workflowPath to POSIX path of (path to me)
        set pathOfInputFile to POSIX path of (input)
        return {workflowPath, pathOfInputFile}
    end run
    Run Shell Script step
    java -jar ${workflowPath}/Contents/Java/my.jar ${pathOfInputFile};

Share This Page