Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Is it possible to get the text of a dock icon's badge label with applescript?

Some OS X dock icons display numbers in their badges. Is it possible to get the number of a specific badge label with applescript? e.g. the count of "Unread Messages" on the Skype dock icon?

Any help would be appreciated

Alex

Posted on Aug 31, 2015 5:54 AM

Reply
1 reply

Sep 2, 2015 5:13 AM in response to LXNdR

There seem to be plenty of examples to set, or update a badge icon out there, but no example of getting the badge icon value. I see this question was asked this week on stackoverflow without any response either.


When I decided to roll my own, it runs, but only returns "missing value" and I am uncertain now if this is how one goes about getting this value, or if there is another approach that I haven't considered. Maybe someone else will correct/contribute, or simply state that it cannot be done.


You create two separate AppleScripts. One is the main AppleScript, and the other is a Library script bundle. The main AppleScript calls the function from the library. The AppKit references are found in NSApplication, and DockTile references. Tested on Mavericks.


Main AppleScript


-- try to get the value of the badge icon

use scripting additions


tell script "Badge_icon"

set bcount to geticonBadgeCount("Skype")

end tell

Library AppleScript (place in /Library/Script Libraries)

-- Script bundle (Badge_icon.scptd) placed in /Library/Script Libraries)

-- Must check AppleScript/Objective-C Library in Bundle Contents Slide out.


on geticonBadgeCount(appName)


tell my applicationappName

activate


set appDockTile to the current application'sNSApp'sdockTile()

set badge_count to appDockTile'sbadgeLabel() as text


end tell

return (badge_count)


end geticonBadgeCount

Is it possible to get the text of a dock icon's badge label with applescript?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.