image
image

|


Go Back   macosx.com > Design, Media, Programming & Scripting > Software Programming & Web Scripting

Reply
 
Thread Tools
  #1  
Old October 18th, 2005, 06:58 PM
Registered User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
vettezuki is on a distinguished road
Make StdC++ Console App Droppable?

New to Mac/OSX programming.

In Windows when dropping a file (of which there are no restrictions) on a conole app, it is the equivalent of calling the application's main function with argv[1] as the full path to the file that was dropped on the app. This is pretty convenient.

I've managed to write a console app in CW that I can explicitly call from the terminal, like so:
$myapp <path_to_input_file>

It works fine (though it opens a separate terminal window for cerr output that does not return control to the calling terminal; I have to command+break to close, but that's a separate question).

However, apparently I have to define a value somewhere (.plc file in CW?) that describes what files are droppable onto the application???

Any help, much obliged.
Reply With Quote
  #2  
Old October 19th, 2005, 01:53 AM
Viro's Avatar
Registered User
 
Join Date: Nov 2003
Location: Oxford, UK
Posts: 2,476
Thanks: 0
Thanked 0 Times in 0 Posts
Viro will become famous soon enoughViro will become famous soon enough
I do not understand how this is supposed to work. If you drag a file to the console, how is it to know what application to call?

As it is, if you drag a file to the Terminal.app, the entire path is copied. Thus, if you have typed $my_app in the terminal, dragging the file you want will cause the path to be placed in the terminal, resulting in $my_app <path_to_file>, which is as far as I can see what you want.

Maybe I'm understanding your question wrong as I've never worked with CodeWarrior.
Reply With Quote
  #3  
Old October 19th, 2005, 04:12 AM
Registered User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
vettezuki is on a distinguished road
Quote:
Originally Posted by Viro
I do not understand how this is supposed to work. If you drag a file to the console, how is it to know what application to call?
Certainly it does not, that's not what I meant.


Quote:
Originally Posted by Viro
As it is, if you drag a file to the Terminal.app, the entire path is copied. Thus, if you have typed $my_app in the terminal, dragging the file you want will cause the path to be placed in the terminal, resulting in $my_app <path_to_file>, which is as far as I can see what you want.

Maybe I'm understanding your question wrong as I've never worked with CodeWarrior.
Same for Windows and Unix. This does work fine. However, in Windows, you can drop anyfile onto a CONSOLE APP and it will call that appp and pass the path to the file that was dropped on it as argv[1].

I would like to do this in OSX.
Reply With Quote
  #4  
Old October 19th, 2005, 08:47 AM
Registered User
 
Join Date: Nov 2000
Posts: 948
Thanks: 0
Thanked 0 Times in 0 Posts
kainjow is on a distinguished road
I don't think it's possible with standard Mac console apps. You need to bundle it into a .app and implement specific functions for accepting a dropped file in Carbon or Cocoa.

What you can do is use an AppleScript to allow someone to drop a file onto the AppleScript, and then have the AppleScript launch the console app. I wrote up a small little script to do this for you. Just open it in Script Editor and Save As an Application so it can be used.

Last edited by kainjow; October 19th, 2005 at 02:36 PM.
Reply With Quote
  #5  
Old October 19th, 2005, 10:02 AM
Viro's Avatar
Registered User
 
Join Date: Nov 2003
Location: Oxford, UK
Posts: 2,476
Thanks: 0
Thanked 0 Times in 0 Posts
Viro will become famous soon enoughViro will become famous soon enough
I honestly do not understand what the OP is describing. Do you mean to say that on Windows, if I drag any file to the command prompt (which is saying something like c:\ with no launched application), it will automatically load up a program (what program?) and pass the path to the file as the first command line argument?

Or do you mean that if you have an application running on the command line, and you drag a file to it, it automatically .... relaunches the application, passing the path to the argv variable?

Neither of these seems plausible and I work on Mac OS X and Linux almost 8 hours every day.
Reply With Quote
  #6  
Old October 19th, 2005, 10:12 AM
Registered User
 
Join Date: Nov 2000
Posts: 948
Thanks: 0
Thanked 0 Times in 0 Posts
kainjow is on a distinguished road
I think what he wants is to be able to drop a file onto a Mac executable and have the executable launch with the path as an argument to the program. He mentions you can do this on Windows, but as I said you can't really do it with a normal Mac console program. You have to do it as Carbon/Cocoa or an AppleScript workaround like I posted.
Reply With Quote
  #7  
Old October 19th, 2005, 01:44 PM
Registered User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
vettezuki is on a distinguished road
Quote:
Originally Posted by kainjow
I think what he wants is to be able to drop a file onto a Mac executable and have the executable launch with the path as an argument to the program. He mentions you can do this on Windows, but as I said you can't really do it with a normal Mac console program. You have to do it as Carbon/Cocoa or an AppleScript workaround like I posted.

You are correct kainjow. Thank you for your time and help. I'll check out the script this afternoon. Something like this is what expected to have to do. Hopefully I'll be able to "package" the end result in such a way that it appears to be a single file to the end user, but one step at a time I'll report later on.
Reply With Quote
  #8  
Old October 19th, 2005, 01:54 PM
Registered User
 
Join Date: Oct 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
vettezuki is on a distinguished road
Quote:
Originally Posted by kainjow
I don't think it's possible with standard Mac console apps. You need to bundle it into a .app and implement specific functions for accepting a dropped file in Carbon or Cocoa.

What you can do is use an AppleScript to allow someone to drop a file onto the AppleScript, and then have the AppleScript launch the console app. I wrote up a small little script to do this for you. Just open it in Script Editor and Save As an Application so it can be used.

Gosh darn it. I'm registered and logged in, but seem to be prevented from downloading this file. When I click on it, it asks me to log in (though I am logged in) and informs I may not have access privelages. What gives?
Reply With Quote
Reply

Thread Tools

Posting 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 Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -5. The time now is 03:05 PM.


Mac Support® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2000-2008 DigitalCrowd, Inc.