Platforms to show: All Mac Windows Linux Cross-Platform
/MacCocoa/NSStatusItem/Display current iTunes Song
Required plugins for this example: MBS MacCocoa Plugin, MBS MacBase Plugin, MBS Util Plugin, MBS MacClassic Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCocoa/NSStatusItem/Display current iTunes Song
This example is the version from Sun, 17th Mar 2012.
Project "Display current iTunes Song.xojo_binary_project"
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
EventHandler Sub Open()
dim f as FolderItem
dim source as String
if TargetMachO=false then
MsgBox "This example needs a MachO target running on Mac OS X."
quit
end if
s=new NSStatusItemMBS
if not s.Available then
MsgBox "NSStatusItem is not available."
quit
end if
call s.CreateMenu
s.HighlightMode=false
s.Title="?"
c=new clock
c.Period=2000
c.mode=2
a=new AppleScriptMBS
a.UnicodeText=true
source= "tell application ""iTunes"""+chr(13)
source=source+"return name of current track"+chr(13)
source=source+"end tell"
a.Compile source
End EventHandler
Function getcurrentsong() As string
dim s as String
a.Execute
s=a.Result
System.DebugLog str(lenb(s))+" "+str(len(s))
System.DebugLog hex(GetEncodingOfStringMBS(s))
Return s
End Function
Sub update()
dim t as String
if s<>Nil then
t=getcurrentsong
if t<>last then
s.title=t
last=t
end if
end if
End Sub
Property Protected a As applescriptmBS
Property c As clock
Property last As string
Property s As NSStatusItemMBS
End Class
Class Clock Inherits Timer
EventHandler Sub Action()
app.update
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS MacCocoa Plugin.