6

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?

chbrown
  • 11,865
  • 2
  • 52
  • 60
  • 1
    My quickfix is to hack it out by adding `LSUIElement1` to `/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/Info.plist`, but that's not very elegant, and not a change I'd want other users to have to do. – chbrown Sep 10 '12 at 17:53
  • Let's get your answer in the answer section if you don't mind. If not, I'd be happy to do it as well. – bmike Jan 16 '14 at 21:12

1 Answers1

4

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.

chbrown
  • 11,865
  • 2
  • 52
  • 60
  • +1 for creativity! But now after having spent 2 hours looking for an answer that actually works, I wonder if it really matters so much. Funny that now that I can easily see how very in-reach the solution is, I realize that I don't care, even though I went through a dozen searches to land here. – ArtOfWarfare Sep 19 '14 at 22:05
  • 1
    @nurp: Apple introduced [SIP](https://support.apple.com/en-us/HT204899) in [OS X 10.11 "El Capitan"](https://en.wikipedia.org/wiki/OS_X_El_Capitan), released on September 30, 2015 (about a year and a half after my original post). The docs on [Configuring System Integrity Protection](https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html) describe how to disable/enable SIP, which as of macOS ≥ El Capitan, you have to do to edit anything in `/System/**/*`. – chbrown Oct 20 '18 at 22:00