Skip to content

Commit

Permalink
fix blueutil in bluetooth.py hardcoded to /usr/local/bin
Browse files Browse the repository at this point in the history
Fixes #10
  • Loading branch information
bmunoz89 committed Sep 29, 2020
1 parent 600b596 commit ae6dcb8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

class BluetoothManager:

__BREW_COMMAND_PATH = '/usr/local/bin/brew'
__BLUETOOTH_COMMAND_PATH = '/usr/local/bin/blueutil'

def __init__(self, wf):
Expand All @@ -41,8 +42,42 @@ def __init__(self, wf):
self._action = self._args[0]
self._action_args = self._args[1:]

self._set_bluetooth_command_path()

self.main()

def _set_bluetooth_command_path(self):
if os.path.exists(self.__BLUETOOTH_COMMAND_PATH):
log.debug('blueutil command path exists')
return

bluetooth_command_path = self._wf.stored_data('bluetooth_command_path')
if bluetooth_command_path is not None:
log.debug(
'blueutil command path stored in "%s" was restored from stored data' %
bluetooth_command_path)
self.__BLUETOOTH_COMMAND_PATH = bluetooth_command_path
return

if not os.path.exists(self.__BREW_COMMAND_PATH):
log.error('brew command path not found')
return

bluetooth_command_path = self._run_command([
self.__BREW_COMMAND_PATH,
'--prefix',
])

if bluetooth_command_path is None:
log.error('blueutil command path not found')
return

bluetooth_command_path += os.path.join(bluetooth_command_path, '/bin/blueutil')
if os.path.exists(bluetooth_command_path):
log.debug('blueutil command path stored in "%s"' % bluetooth_command_path)
self._wf.store_data('bluetooth_command_path', bluetooth_command_path)
self.__BLUETOOTH_COMMAND_PATH = bluetooth_command_path

def _run_command(self, command):
log.debug('Command: "%s"' % ' '.join(command))
output = self._wf.decode(run_command(command)).strip()
Expand Down
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ brew install blueutil</string>
</dict>
</dict>
<key>version</key>
<string>2.0.0</string>
<string>2.0.1</string>
<key>webaddress</key>
<string>https://github.com/bmunoz89/alfred-wf-bluetooth-manager</string>
</dict>
Expand Down

0 comments on commit ae6dcb8

Please sign in to comment.