Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Agent Moose

macrumors newbie
Original poster
Dec 1, 2012
7
0
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:
Code:
./configure --disable-gifview --disable-gifdiff
make
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?
 
Very Newbish Question

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:
Code:
./configure --disable-gifview --disable-gifdiff
make
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?

Some people have a bone to pick with you. :D
 
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:
http://sveinbjorn.org/platypus

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.

EDIT
Before attempting anything with Platypus, be sure to read its documentation.
http://sveinbjorn.org/files/manpages/PlatypusDocumentation.html
 
Last edited:
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:
Code:
#!/bin/bash

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:
Code:
./gifsicle -bl

Will look like this when it is actually ran.:
Code:
./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

Edit:
I also have it set so that I can just drag and drop the file I want to edit, over the application.
 
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:
Code:
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.
 
And that worked beautifully, Thank you!

I shall look more into the tutorials and what not for later use ^^
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.