Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Mar 29, 2020 1:06 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:07 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
It took a little bit of poking around to figure out how to do this properly, so I thought I would share with others.
This little snippet will add your application to the current users dock. You need to do your own error handling. It is not dependent on plugins.
Dim origin as FolderItem = app.executableFile.parent.parent.parent
dim s as string = "Volumes/"+ReplaceAll(origin.AbsolutePath,":","/")
dim myShell as new shell

myShell.Execute "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" +s+"</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
myShell.Execute "osascript -e 'tell application """+"Dock"+""" to quit'"


The last line will quit the users Dock, which will then automatically relaunch, which will force the Dock to update and show your icon. Quitting the Dock has a few undesired effects:
1) minimized windows will be restored
2) Anecdotally, in some earlier OSs you may need to add this line at the end of the example myShell.Execute "osascript -e 'tell application """+"Dock"+""" to Activate'" to make the Dock relaunch. I don't have anything early enough to test that - on all my systems the Dock does as expected and relaunches.

Please feel free to critique and add your own ideas.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:18 am 
Offline
Site Admin
User avatar

Joined: Tue May 06, 2008 1:07 pm
Posts: 1464
Location: NotEvenOnTheMap, CT
Personally, I think screwing with the user's dock is a really evil tactic. It reminds me of Adobe Reader always putting itself on my Windows desktop every time it auto-updates. Of all the useless things, why would I want Adobe Reader on the desktop?

Anyway, use this with care. Provide an option to your customers, don't just do it.

_________________
Thom McGrath - @tekcor
Web Framework Architect, Real Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:23 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
And from Apple the LSSharedFileList* APIs are for this kind of work.
You can use our LSSharedFileListMBS plugin class for this.

Messing with another app's preference is not a good idea.

PS: The path you add to the dock preferences for you app is certainly wrong.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:28 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
I agree this should not be done without consent, nor should any other action.

Firstly I check where the Application is running from and if its not in the Application folder or a subfolder of the aforementioned it offers to move itself to the Applications folder (or ~/Applications folder for users with limited permissions or network users). This helps newbies who tend to run everything from the Downloads folder :wink:
I also offer to create an alias in the Dock, again to help newbies.

Both these are at the users behest, none are done without a prompt. My prompt clearly explains its proposed action, and offers very clear "Yes", "No" and "Decide Later" options.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:29 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
MonkeybreadSoftware wrote:
PS: The path you add to the dock preferences for you app is certainly wrong.


Give a dog a bone and explain why you believe it is wrong.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:43 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Because your string starts with "Volumes". I'd expect it to start with a slash and only have "/Volume/" if the file is not on the boot volume.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:51 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
MonkeybreadSoftware wrote:
Because your string starts with "Volumes". I'd expect it to start with a slash and only have "/Volume/" if the file is not on the boot volume.


The boot volume is in /Volumes/ so is that really wrong, or is it a little too literal for your liking. Is 'wrong' a little unfair? I tried to keep it simple so you can add the icon from any volume.


MonkeybreadSoftware wrote:
And from Apple the LSSharedFileList* APIs are for this kind of work.
You can use our LSSharedFileListMBS plugin class for this.


Can you post a link to where you show how to do this with your plugin, I own a complete license of your plugin and didn't realize you had something already done, I'm having trouble finding an example on your site. Thanks.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 10:57 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
Hi,

well, if you go the way using Volume for the boot volume, your code will break unnecessarily if the user renamed the boot volume.

The class is described here:

http://www.monkeybreadsoftware.net/clas ... tmbs.shtml

and an example is here:

http://www.monkeybreadsoftware.net/exam ... test.shtml

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 11:33 am 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
MonkeybreadSoftware wrote:
if you go the way using Volume for the boot volume, your code will break unnecessarily if the user renamed the boot volume.


But Volumes is not the name of the boot volume, it is the location that all volumes reside in. So in my example an application called MBS in the Applications folder of my boot volume called "Mac HD" would become:
/Volumes/Mac HD/Applications/MBS.app/


MonkeybreadSoftware wrote:


Do you have an example that actually adds an applications icon to the Dock? I read your class description, buts its verbatim of Apples LSShaedFileList description.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 11:59 am 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
I'm sorry. Editing the dock is not in LSSharedFileList. My mistake.

The difference for the pathes is:

/Volumes/Mac HD/Applications/MBS.app/
vs.
/Applications/MBS.app/

First will fail if disc name changes.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 12:18 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
MonkeybreadSoftware wrote:
/Volumes/Mac HD/Applications/MBS.app/
vs.
/Applications/MBS.app/
First will fail if disc name changes.


I don't understand. /Volumes/ never changes, its where volumes are. The only 'hard coded' part of my example is "/Volumes/".
Is this a localization issue? Does the German OS not use /Volumes ???

The /Volumes directory is the mount point for all of the drives. The Volumes directory is populated with directories corresponding to the names of Volumes on your system. If you insert a USB Thumb Drive, a new directory in /Volumes is created with the name of the USB Thumb Drive. These directories are called "mountpoints", and are created on-the-fly by Apple's autodiskmount utility.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 12:24 pm 
Offline
User avatar

Joined: Wed May 10, 2006 2:42 pm
Posts: 2985
Location: Germany
If you rename "Mac HD", the name of the symbol link there will change in the Volumes folder. That's the point.

Greetings
Christian

_________________
See you in Orlando, Florida for Real World 2013
More details and registration here:
http://www.realsoftware.com/community/realworld.php


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 12:30 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
ahhhh, I see what you mean.

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X Tip: Add your application to the Dock
PostPosted: Tue Aug 31, 2010 1:05 pm 
Offline
User avatar

Joined: Sat Nov 11, 2006 2:43 pm
Posts: 1221
Location: This poster has left the forums
Revised code
Dim origin as FolderItem = app.executableFile.parent.parent.parent
dim s as string = "Volumes/"+ReplaceAll(origin.AbsolutePath,":","/")
dim myShell as new shell

myShell.Execute "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" +s+"</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
myShell.Execute "osascript -e 'tell application """+"Dock"+""" to quit'"

_________________
%Invalidforumsignatureexception% user signature not found


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group