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

jpanetta

macrumors newbie
Original poster
May 1, 2006
6
0
I'm writing a url helper to automatically access files on an SMB server from a web browser. It works by checking if the share on the server is already mounted, and mounting it in the /Volumes/ directory if it isn't. This all works fine, but the mounted volume does not show up on the desktop. To allow people to connect/disconnect/browse shares mounted by the url helper, I have made a window with a list of all the connected shares. From here, the user can double click on the share to browse it in the finder, or click disconnect to unmount it. This all either works already or will work soon, but I'm wondering how I can prevent this window from displaying when my application is launched by a web browser. I have the getUrl method quit the application, but the window still briefly flashes on the screen (annoying). Is there an object I can query to determine if my application was launched by a double-click or not?

Thanks a lot,
Julian
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
Can you access the command line arguments used to launch your app and use those to distinguish when the app was launched by double-clicking and when the browser launched it?

Also, your comment about the volumes not showing up on the desktop caught my eye because the other day I saw this tech note on Apple's site. I don't know if it has anything to do with your problem, but here's a link: http://developer.apple.com/qa/qa2006/qa1491.html
 

jpanetta

macrumors newbie
Original poster
May 1, 2006
6
0
Can you access the command line arguments used to launch your app and use those to distinguish when the app was launched by double-clicking and when the browser launched it?

Also, your comment about the volumes not showing up on the desktop caught my eye because the other day I saw this tech note on Apple's site. I don't know if it has anything to do with your problem, but here's a link: http://developer.apple.com/qa/qa2006/qa1491.html

Looking at the arguments was a good idea, but it doesn't seem to be of much help. The only argument passed (other than the path of the executable at argv[0]) was a string reading "-psn_0_#" where the # was an 8 digit number that had increased every time I launched the app (could this be the tick count of the cpu since boot?). This same argument was passed from the finder and the web browser, so I don't see any way of using it to differentiate between the two. It seems there MUST be some way, though; how do document-based applications differentiate between being launched from a double-clicked file and being double clicked themselves? I know they are able to perform a default action if they aren't opened by a file. I feel all this stuff is something I really should know, but I guess I haven't spent enough time on cocoa!

The article you linked seems interesting but not quite what I need. Plus, after searching around the web before starting my program, I decided that getting the finder to display my mount_smbfs mounted shares was not going to happen--at least not without a good deal of effort.

Thanks for your help!
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Why not tell the application to not display the window by default when the application launches and get the "getURL" method to display the window if necessary?
 

jpanetta

macrumors newbie
Original poster
May 1, 2006
6
0
Why not tell the application to not display the window by default when the application launches and get the "getURL" method to display the window if necessary?

I DON'T want the window displayed when getURL is called :p--that is, when the program is called by a web browser, I want it to be as unnoticeable as possible.

I've tried getting the window to display by default and then having getURL hide it. There is too much of a gap in time between the program launching and getURL being called for this to occur "invisibly."
 

jpanetta

macrumors newbie
Original poster
May 1, 2006
6
0
EXCELLENT!

I just figured out how to do it :). After browsing Apple's documentation about NSApplication, I decided to see if the applicationOpenUntitledFile: message sent to a delegate is only sent if the application is opened without a URL. Thankfully, Mac OS X treats a URL as a file when informing my application whether or not it was supplied a file at startup. So I just have my applicationOpenUntitledFile: open the window. To speed launch time (it's fast on my macbook pro, but might run slower on my user's computers), I'll probably split off all the window code from the main nib and only load it in the applicationOpenUntitledFile.

Thanks for the help anyway!
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
I actually sent you that answer via ESP, but I just forgot to post here too. ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.