Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added PluginDirectories/1/connect.bundle/Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions PluginDirectories/1/connect.bundle/examples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
connect(connect) ~device(bluetooth device)
connect(cn) ~device(bluetooth device)
disconnect(disconnect) ~device(bluetooth device)
disconnect(dis) ~device(bluetooth device)
toggle(toggle) ~device(bluetooth device)
toggle(tg) ~device(bluetooth device)
toggle(bt) ~device(bluetooth device)
10 changes: 10 additions & 0 deletions PluginDirectories/1/connect.bundle/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "connect",
"displayName": "Connect",
"description": "Connect/Disconnect bluetooth device",
"examples": ["connect Magic Keyboard", "cn keyboard", "disconnect Magic Mouse", "dis mouse", "tg airpods", "bt airpods"],
"categories": ["Utilities"],
"openPreferencesOnInstall": true,
"creator_name": "EARTHPYY",
"creator_url": "https://www.earthpyy.com"
}
13 changes: 13 additions & 0 deletions PluginDirectories/1/connect.bundle/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"options": [
{
"type": "table",
"text": "Alias:",
"key": "devices",
"columns": [
{"text": "Alias", "key": "alias"},
{"text": "Device name", "key": "fullname"}
]
}
]
}
31 changes: 31 additions & 0 deletions PluginDirectories/1/connect.bundle/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os, json, commands

def run(cmd):
os.system(cmd)

def results(fields, original_query):
settings = json.load(open('preferences.json'))
devices = settings["devices"]
device_name = str(fields.get("~device"))

for device in devices:
if device_name.lower() == device["alias"].lower():
device_name = device["fullname"]
break

command = "osascript toggle.applescript \"{0}\"".format(device_name)
if "connect" in fields:
return {
"title": "Connect " + device_name,
"run_args": [command + " Connect"]
}
elif "disconnect" in fields:
return {
"title": "Disconnect " + device_name,
"run_args": [command + " Disconnect"]
}
elif "toggle" in fields:
return {
"title": "Toggle " + device_name,
"run_args": [command + " Toggle"]
}
12 changes: 12 additions & 0 deletions PluginDirectories/1/connect.bundle/preferences.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"devices" : [
{
"alias" : "keyboard",
"fullname" : "Magic Keyboard"
},
{
"alias" : "mouse",
"fullname" : "Magic Mouse"
}
]
}
24 changes: 24 additions & 0 deletions PluginDirectories/1/connect.bundle/toggle.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on run argv
set device_name to item 1 of argv
set action_name to item 2 of argv
tell application "System Events"
tell process "SystemUIServer"
tell (menu bar item 1 of menu bar 1 where description is "bluetooth")
click
if menu item device_name of menu 1 exists then
tell (menu item device_name of menu 1)
click
set menu_name to name of menu item 1 of menu 1
if action_name is "Toggle" or action_name is menu_name then
click menu item 1 of menu 1
else
key code 53
end if
end tell
else
key code 53
end if
end tell
end tell
end tell
end run