Thanks for the explanation, I can't remember all I tried back then, but it seems like I missed trying it like this!
Since the part for Wifi and launching/quitting applications with it is working fine now, is there any chance you could help me with creating a script for doing the same for bluetooth? It doesn't seem to work with just changing the network card in the lines from wifi and the script I found on the internet is rather.. inefficient (slow, and uses quite some code). So, the only reason I'm using this, is because I couldn't make it work otherwise and also couldn't find any better hints anywhere. Again, I don't remember where I found this code. Just some copy&paste work I did a while ago.
The script I'm currently using (python):
import sys, objc
import time
from CoreFoundation import *
IOBT_BRIDGESUPPORT = '''<?xml version="1.0" standalone="yes"?>
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version="0.9">
<function name="IOBluetoothPreferenceGetControllerPowerState">
<retval type="i"></retval>
</function>
<function name="IOBluetoothPreferenceSetControllerPowerState">
<arg type="i"></arg>
<retval type="i"></retval>
</function>
</signatures>'''
objc.initFrameworkWrapper(
frameworkName="IOBluetooth",
frameworkIdentifier="com.apple.Bluetooth",
frameworkPath=objc.pathForFramework('/System/Library/Frameworks/IOBluetooth.fra mework'),
globals=globals()
)
objc.parseBridgeSupport(
IOBT_BRIDGESUPPORT,
globals(),
objc.pathForFramework('/System/Library/Frameworks/IOBluetooth.framework')
)
def set_ioblpstate(s):
# int s : 0 = off, 1 = on
IOBluetoothPreferenceSetControllerPowerState(s)
s1 = -1
for i in range(50):
s1 = get_ioblpstate()
if s1 == s:
break
time.sleep(0.1)
if s1 != s:
sys.stderr.write('Unable to set bluetooth power state to %s\n' % ('off' if s == 0 else 'on').encode('utf-8'))
sys.exit(1)
return s1
def get_ioblpstate():
return IOBluetoothPreferenceGetControllerPowerState()
def main():
print '%d' % set_ioblpstate(1 if get_ioblpstate() == 0 else 0)
sys.exit(0)
main()