Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Python rocket dock icon when using ScriptingBridge

I'm retrieving the current track playing in iTunes, Mac OS X, with ScriptingBridge.

from ScriptingBridge import SBApplication
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
print iTunes.currentTrack().name()

But when I run that last line, actually getting the track name, an application appears in the dock, and doesn't leave until I close my Python program, whether I'm running it in the REPL or as a script. The icon is this one, at least on my machine:

/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/Resources/PythonInterpreter.icns

The script works great, and I can get all the info I need from iTunes via SB. I would just like to keep the icon from popping up. Why does that particular method call invoke a dock icon?

like image 713
chbrown Avatar asked Oct 06 '22 16:10

chbrown


1 Answers

A hacky way to get it off the dock is to prevent Python.app from ever showing up on the dock:

Edit /System/Library/Frameworks/Python.framework/Versions/Current/Resources/Python.app/Contents/Info.plist and add this key-value pair to the main <dict> element:

<key>LSUIElement</key><string>1</string>

I wish there were another way to do this, because this change is global — no Python script (using the system Python) will ever show up on the dock with this setting. Since posting this question I have set my LSUIElement back to 0, because there's no other way to grab, for example, a matplotlib-produced window, unless it has an icon in the dock.

like image 52
chbrown Avatar answered Oct 10 '22 17:10

chbrown