Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Attach desktop icon to darwin command?

Attach desktop icon to darwin command?
Thread Tools
Fresh-Faced Recruit
Join Date: Aug 2002
Location: Fillmore, CA
Status: Offline
Reply With Quote
Nov 19, 2002, 09:08 PM
 
I know this has to be easy, but how can I create a desktop icon that will function as a drag/drop interface to a darwin command? Specifically, I have ghostscript installed and want to create a simple desktop drag/drop interface to the ps2pdf command (ps2pdf inputfile.ps outputfile.pdf)

I'm really unclear on the relationship between Applescript and Darwin.

Thanks!
...---...---...---...---...---...---...
The early bird may get the worm, but the early worm gets eaten!
     
Mac Elite
Join Date: May 1999
Location: San Jose, CA
Status: Offline
Reply With Quote
Nov 20, 2002, 04:48 AM
 
There is no direct correlation between AppleScript and Darwin. In this case, AppleScript should be thought of more like perl in that you'll do what you want by writing an AppleScript to call GhostScript for you.

A simple example would be:

on open these_items
repeat with this_item in these_items
do shell script "ps2pdf \"" & this_item & "\" outfile.pdf"
end repeat
end open

Save this script as a Script Application (an option in the Save dialog in the Script Editor) and you now have a complete drag-and-drop application.

The logic of the script is:

on open these_items

The files dropped on the icon are placed in an list (array) called "these_items". Note, this automatically supports multiple files dropped at the same time.

repeat with this_item in these_items

This AppleScript repeat statement loops through the items in "these_items" sequentially. For each iteration, the current item is stored in a variable called "this_item". The loop automatically terminates when there are no more items in the list.

do shell script "ps2pdf \"" & this_item & "\" outfile.pdf"

This is the line that concatenates the name of the current file (this_item) into the command line "ps2pdf <filename> outfile.pdf", which it then passes to a new shell for execution.
Note that I've quoted the input filename, just in case the file (or its path) contains spaces which would confuse the shell. Also, this simple script always outputs to the same file, namely "outfile.pdf". A more robust script would probably generate an output filename based on the input filename, but I'll leave that up to you.

end repeat

Simply the end of the repeat loop.

end open

and the end of the script.
Gods don't kill people - people with Gods kill people.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:22 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2