Very Newbish Question

Discussion in 'Mac Programming' started by Agent Moose, May 25, 2014.

  1. Agent Moose macrumors newbie

    Dec 1, 2012
    I've worked with Javascript and other website based scripts, but never anything OS related.

    So, my question is how do I create a program that will run when I drag another file onto it?

    I have Gifsicle (a command line application that makes gifs) and I want to be able to just drag and drop the images I want to edit (all the images will be edited with the program the same way, so yeah)

    This is what I have to type in to the command line to make it work:
    ./configure --disable-gifview --disable-gifdiff
    cd src
    ./gifsicle -bl /path/to/image.gif
    And obviously I need to be in the directory with all the files.

    So, is there anyway I can make this happen?
  2. macs4nw macrumors 601


    Some people have a bone to pick with you. :D
  3. chown33, May 25, 2014
    Last edited: May 25, 2014

    chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    First, it's not necessary to run configure and make every time. That's only necessary the first time. After that, the program gifsicle exists and can be reused. If you don't know how to do that, then ask again.

    Second, you could use the Platypus tool to make just such an app:

    AFAIK it still works.

    Obviously, you need to know enough about command-lines, where to place command-line tools, etc. that you can build a suitable command-line for Platypus to work with. If you need help with that (and my guess is you will), then feel free to ask again with specific questions.

    Third, there's a difference between opening a command-line tool the first time (i.e. dropping a file on an unlaunched app), and dropping subsequent files on the app's icon in either a Finder window or on its Dock icon. There's a fundamental and insurmountable difference between the two ways of communication file-names to apps. Platypus can mediate launch-the-app drops, but it can't mediate open-file-in-running-app drops.

    Before attempting anything with Platypus, be sure to read its documentation.
  4. Agent Moose thread starter macrumors newbie

    Dec 1, 2012
    Sorry about the misleaded thread title. I really should of known since I have been an admin and such on many forums over the years.

    Anyway, I did try out Platypus and I didn't get it working.

    I set the script type as bash, and in the script I did this:
    cd ~/Documents/gifsicle/src
    ./gifsicle -bl
    Under the arguments, I added "-l" to the end to get the location of the item I want edited, but it didn't edit the file I needed. It didn't edit anything.

    Pretty much I need to make it so this line:
    ./gifsicle -bl
    Will look like this when it is actually ran.:
    ./gifsicle -bl /path/to/file.gif

    I even tried added the -l argument after the said above line and it still didn't work. I have no clue what I am doing wrong. It seems like it's something simple. :p

    I also have it set so that I can just drag and drop the file I want to edit, over the application.
  5. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Did you look at any of the Platypus examples? SpeakDroplet accepts files dropped on it. You should do like it does.

    FWIW, you can also use Automator to run a command-line tool while accepting files dropped on it. This might be simpler than using Platypus, at least starting out.

    The basic procedure in Automator is this:
    1. Choose to create an Application.
    2. Add a single Run Shell Script step.
    3. Change "Pass input:" to "as arguments".
    4. Replace the entire prototype shell script with this:
    cd ~/Documents/gifsicle/src
    ./gifsicle -bl "$@"
    The magical "$@" basically means "all the things dropped on it" in this context.

    You can learn more about Automator by choosing "Display Automator Website" from its Automator menu. Or search for Automator tutorials.
  6. Agent Moose thread starter macrumors newbie

    Dec 1, 2012
    And that worked beautifully, Thank you!

    I shall look more into the tutorials and what not for later use ^^

Share This Page