Automator Help: Get item location

Discussion in 'Mac Programming' started by JesseW6889, Feb 25, 2012.

  1. macrumors 6502

    Joined:
    Dec 12, 2010
    #1
    I've got some programming background but don't quite know my way around automator. I am a iOS application developer, and I test my apps on my jailbroken iPhone, but they need to be code signed first, which consists of running a command in terminal to the location of the .app file, which is kind of a pain in the butt, but this is my routine now...

    1. Copy and paste this script into terminal:
    Code:
    codesign -fs "Cydia Developer" /path/appname.app/appname
    2. Replace the '/path/appname.app/appname' with the path and name of app
    Code:
    codesign -fs "Cydia Developer" '/Users/jessew/Desktop/Switch Views.app/Switch Views'
    3. Execute

    How would I automate this, by say, dragging and dropping the file or (preferably) the folder and have automator copy the location and append that to the 'codesign -fs "Cydia Developer"' code. It seems like it should be pretty easy, but I don't know how to do it!

    Any help would be MUCH appreciated, its a pain in the butt to do EVERY time I want to try an app on my phone... thanks!
     
  2. chown33, Feb 25, 2012
    Last edited: Feb 25, 2012

    macrumors 603

    Joined:
    Aug 9, 2009
    #2
    Since you already know how to write shell scripts (or so it seems), you can simply wrap a shell script into a drag-n-drop wrapper, like Platypus. You have to put a little code at the head of the script, to accept the dropped items as normal command-line parameters, but after that it's just like a normal shell script.

    Here's an example I use:
    Code:
    #!/bin/bash
    
    #printenv | sort
    
    ## Under Platypus, $1 is path to app-bundle.
    ## MUST NOT process that.
    ## Relies on env-var APP_BUNDLER being set to "Platypus*"
    APP_DIR="$PWD"
    
    if [[ "${APP_BUNDLER:0:8}" = "Platypus" ]]
    then
      APP_DIR="$1/.."
      shift
      echo ".. Platypus at: $APP_DIR"
    fi
    
    
    
    # This script strips all ".DS_Store" files from a subtree.
    # This is most often useful on app-bundles.
    
    # echo "$@"
    
    for item in "$@"
    do
      if [ -d "$item" ]
      then
        echo "Directory: " "$item"
        find "$item" -name ".DS_Store" -print -delete
      fi
    
    done
    
    The original script I developed starts at the "This script strips all ..." comment. The preface is boilerplate I use in several Platypusified scripts, for detecting that they're running under Platypus. If it's not obvious, I have the APP_BUNDLER env-var set under Platypus, but NOT set in my normal Terminal shell (unless I'm testing it in an environment like Platypus).
     

Share This Page