Tuesday, September 2, 2014

#1 2011-01-04 12:14:42 pm

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

How to add a badge to your app's dock icon...

I converted an objective-c example to ASOC that demonstrated how to add a badge to your dock icon. Thought it might be useful to someone. Here is the code:

Applescript:

on setDockBadgeString_(dockBadgeString)
   set appDockTile to current application's NSApp's dockTile()
   appDockTile's setBadgeLabel_(dockBadgeString)
end setDockBadgeString_

You simply call it like this from your code:

Applescript:

my setDockBadgeString_("9999")

Documentation says to pass a string. Didn't try with an integer or float yet, could work. Also, if you want to remove the badge, call the routine again by passing "" or missing value.

Enjoy!

P.S.: I'm madly in love with AppleScriptObjC!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Offline

 

#2 2011-01-20 03:46:06 pm

evocomps
Member
From: Oklahoma
Registered: 2007-10-15
Posts: 119
Website

Re: How to add a badge to your app's dock icon...

That is awesome. I've always been curious how this was done.

Offline

 

#3 2011-01-20 05:45:53 pm

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Ain't it! It's awesome indeed... and so easy! Eventually I want to figure out how to add things like progress bars or other elements over the dock icon. I'll post my successes on these forums of course...

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Offline

 

#4 2011-01-21 10:51:54 pm

Dylan Weber
Member
From: IL, USA
Registered: 2009-08-07
Posts: 539

Re: How to add a badge to your app's dock icon...

leonsimard wrote:

Ain't it! It's awesome indeed... and so easy! Eventually I want to figure out how to add things like progress bars or other elements over the dock icon. I'll post my successes on these forums of course...

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

I believe progress bars are done from pre-generated images of the icon with bars, so you'd just be temporarily setting the icon to another image.


I am addicted to this site.
Look, over 500 posts! I barley help! :O
My specialty is replacing common AppleScript commands with hard-to-work-with methods.

Offline

 

#5 2011-01-22 07:28:33 am

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

I don't know, sounds like it. I know this method of NSDockTile will do the trick:

Applescript:

- (void)setContentView:(NSView *)view

So I guess I'll have to create an NSView in IB and then assign it with this method to the dock's icon and tell it to display itself. I can't do any testing yet, but for sure i'm gonna try it! Too exciting!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Offline

 

#6 2012-07-11 07:43:02 am

Delivery Boy
Member
Registered: 2012-07-11
Posts: 1

Re: How to add a badge to your app's dock icon...

leonsimard wrote:

I converted an objective-c example to ASOC that demonstrated how to add a badge to your dock icon. Thought it might be useful to someone. Here is the code:

Applescript:

on setDockBadgeString_(dockBadgeString)
   set appDockTile to current application's NSApp's dockTile()
   appDockTile's setBadgeLabel_(dockBadgeString)
end setDockBadgeString_

You simply call it like this from your code:

Applescript:

my setDockBadgeString_("9999")

Documentation says to pass a string. Didn't try with an integer or float yet, could work. Also, if you want to remove the badge, call the routine again by passing "" or missing value.

Enjoy!

P.S.: I'm madly in love with AppleScriptObjC!

Browser: Safari 531.22.7
Operating System: Mac OS X (10.6)

Hello,

what do I need to get your example to work?
My AppleScript returns the error: "NSApp doesn’t understand the dockTile message."
Thanks.


Regards,
Delivery Boy

Model: MacBook Pro
AppleScript: 2.2.1
Browser: Safari 534.57.2
Operating System: Mac OS X (10.7)


Filed under: icon badge

Offline

 

#7 2012-07-11 09:31:24 am

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Nothing special. Works just fine in any ASOC application. The trick it to call NSApp (which is just the short version of NSApplication). NSapp is your application, currently running. So you're telling it to get its dock icon, then set a badge onto it. As far as I know, this is part of appkit, so there's no need to import any framework or libraries.

Which version of Xcode are you working on?

Offline

 

#8 2012-07-11 05:17:57 pm

fiz
Member
From: Lausanne, Switzerland
Registered: 2011-03-02
Posts: 849

Re: How to add a badge to your app's dock icon...

leonsimard wrote:

P.S.: I'm madly in love with AppleScriptObjC!

So was I. Objective-C says just:

[[NSApp dockTile] setBadgeLabel: @"9999"];

Anywhere in the code. Objective-C, I'm crazy about you smile


Bernard

Offline

 

#9 2012-07-11 06:05:04 pm

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Same here! Furiously in love with objective-c now! All thanks to applescriptobjc!

Soooo much better... And the speed! The speed! I still use ASOC when I need to talk to other apps, but recently I found how to use scripting bridge in objc. There's a tool that converts the AppleScript dictionary of an app (sdef) and creates a .h file with it. Genius! So I think that in the not too far future it'll be bye bye AppleScript... Our love was good, but I found better smile

Last edited by leonsimard (2012-07-11 06:05:45 pm)

Offline

 

#10 2012-07-11 06:32:21 pm

fiz
Member
From: Lausanne, Switzerland
Registered: 2011-03-02
Posts: 849

Re: How to add a badge to your app's dock icon...

Our love was good, but I found better

For me, ApplescriptObjC is the first stage of the Objective-C rocket. I would never have a takeoff without it.

I think this "bridge" is a brilliant idea: you come from Applescript, you enter the ASOC door to Cocoa, and you start learning the framework without noticing it, translating them into your loved Applescript syntax. And after a year, tired to coerce your variables, you find yourself programming in a language you would never dare to deal with…

The second stage is, of course, this forum. It is cleverly built, and you get fast answers from very skilled people. Have a look on other Objective-C sites and you will know what I'm talking about…


Bernard

Offline

 

#11 2012-07-11 07:02:28 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3594

Re: How to add a badge to your app's dock icon...

leonsimard wrote:

recently I found how to use scripting bridge in objc. There's a tool that converts the AppleScript dictionary of an app (sdef) and creates a .h file with it. Genius!

I suggest you hunt around a bit. Genius is definitely not the word most used to describe it...


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#12 2012-07-11 07:16:54 pm

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

I meant for the tool to convert the sdef file... I haven't started playing around with it, i'll start with simple tasks and medium-sized apps like Numbers before attacking bigger ones like InDesign.

But at least, that's a start. I had nothing before, so I consider this great, been looking for awhile... smile

Offline

 

#13 2012-07-11 07:25:09 pm

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Oh, and besides these forums, I find Stack Overflow to be of nice help, most questions I have have beeen answered in one form or another in the past (mostly because of my beginner level limitations wink ), and people are usually quite friendly... usually.

Offline

 

#14 2012-07-11 07:45:16 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3594

Re: How to add a badge to your app's dock icon...

leonsimard wrote:

I haven't started playing around with it

You might want to start here: cocoadev.com/wiki/ScriptingBridgeCriticisms


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#15 2012-10-04 01:12:55 am

edp
Member
Registered: 2012-10-03
Posts: 5

Re: How to add a badge to your app's dock icon...

Hi,

is it possible to have an example of the applescript?
If I execute, it dosn't appear the badge number on the applescript editor icon.

Offline

 

#16 2012-10-04 01:17:47 am

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3594

Re: How to add a badge to your app's dock icon...

What code did you try?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#17 2012-10-05 04:53:57 am

edp
Member
Registered: 2012-10-03
Posts: 5

Re: How to add a badge to your app's dock icon...

I tried this:

Applescript:

on setDockBadgeString_("9")
   set appDockTile to current application's NSApp's dockTile()
   appDockTile's setBadgeLabel_("9")
end setDockBadgeString_

Should it add a [9] badge on the Applescript Editor app icon?

I'm a noob in AppleScript...

Offline

 

#18 2012-10-05 06:12:54 am

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Look at post #1, there is is two parts to this. There's a method that you put somewhere in your code then you call this method with the second part.

Btw, this is applescriptobjc, not plain AppleScript. Thus your project needs to be done under Xcode or Shane's app, AppleScript explorer if I remember correctly.

Offline

 

#19 2012-10-05 07:26:45 am

edp
Member
Registered: 2012-10-03
Posts: 5

Re: How to add a badge to your app's dock icon...

Is it Applescript Studio?
Basically I want to add the badge icon to the FileMaker Icon in the dock.
maybe this post can help you to help me? :-P
http://macscripter.net/viewtopic.php?id=36605

Offline

 

#20 2012-10-05 07:29:29 am

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

Nope, this is not AppleScript Studio. AppleScript Studio has been deprecated when OS X Snow Leopard came out a few years ago. It's replacement is AppleScriptObjC, which is completely different, but a huge improvement.

And sorry, but you can't add a badge to another app (as far as I know). This code is for your own app while it's running, and will not work the way you want it to. Sorry.

Offline

 

#21 2012-10-05 07:32:07 am

edp
Member
Registered: 2012-10-03
Posts: 5

Re: How to add a badge to your app's dock icon...

neither if FileMaker can run applescript itself?

Offline

 

#22 2012-10-05 07:36:23 am

leonsimard
Member
From: Montreal, Canada
Registered: 2009-09-27
Posts: 498

Re: How to add a badge to your app's dock icon...

This is what I've been saying. This is not plain AppleScript. In your case, if there is no AppleScript command built into the application to set it's dock badge icon, then there is no other way to do it. I've never seen it before, not would I know how to do it. I could be wrong, but one thing is for sure, you cannot do it with AppleScript, and neither with AppleScriptObjC, unless in this case the app talks to itself, not other apps.

Offline

 

#23 2012-10-05 07:44:03 am

edp
Member
Registered: 2012-10-03
Posts: 5

Re: How to add a badge to your app's dock icon...

Ok, thank you

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.115 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)