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