-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/.idea/scopes/generated.xml b/.idea/scopes/generated.xml
new file mode 100644
index 0000000..d1aae9b
--- /dev/null
+++ b/.idea/scopes/generated.xml
@@ -0,0 +1,3 @@
+
+
+
diff --git a/.idea/scopes/lib.xml b/.idea/scopes/lib.xml
deleted file mode 100644
index cbb1c8b..0000000
--- a/.idea/scopes/lib.xml
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-
diff --git a/.images/Browser Confirmation.png b/.images/Browser Confirmation.png
new file mode 100644
index 0000000..b8fb054
Binary files /dev/null and b/.images/Browser Confirmation.png differ
diff --git a/.images/Example.png b/.images/Example.png
new file mode 100644
index 0000000..482f76d
Binary files /dev/null and b/.images/Example.png differ
diff --git a/.images/Script Filter.png b/.images/Script Filter.png
new file mode 100644
index 0000000..5be5158
Binary files /dev/null and b/.images/Script Filter.png differ
diff --git a/7D9DF57A-5DF9-5DB9-AB88-88DAC6AD7FB1.png b/7D9DF57A-5DF9-5DB9-AB88-88DAC6AD7FB1.png
index 4975a05..0e6ed8c 100644
Binary files a/7D9DF57A-5DF9-5DB9-AB88-88DAC6AD7FB1.png and b/7D9DF57A-5DF9-5DB9-AB88-88DAC6AD7FB1.png differ
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..c178261
--- /dev/null
+++ b/README.md
@@ -0,0 +1,67 @@
+# Py3 Default Browser
+
+This [Alfred](https://www.alfredapp.com) workflow makes it simple to change your default
+browser on macOS.
+
+
+
+## Installation
+
+To install this workflow you just have to download and open the `.alfredworkflow` file
+from the latest
+release [here](https://github.com/wmorland/alfred-py3-default-browser/releases/latest).
+The Alfred website's Help section has more information about
+Workflows [here](https://www.alfredapp.com/help/workflows/#discovering). Workflows are a
+paid feature of Alfred which require
+the [Alfred Powerpack](https://www.alfredapp.com/powerpack/).
+
+## Usage
+
+The default shortcut is `db` and you can then pick a browser from the list of available
+options. macOS requires you to confirm the change in a pop up dialog. For
+example:
+
+
+
+### Changing the Alfred keyword
+
+1. Open Alfred Preferences and go to 'Workflows' > 'Py3 Default Browser'.
+2. Double click on the Script Filter
+ component.
+
+
+
+3. Change the keyword field to your new chosen keyword (you can leave all other fields
+ the same) and then click 'Save'.
+
+## Support
+
+If you have any questions or feature requests then
+please [file an Issue](https://github.com/wmorland/alfred-py3-default-browser/issues/new)
+on GitHub or reach out to me on Twitter, [@w_morland](https://twitter.com/w_morland).
+
+## Contributing
+
+Pull requests are welcome. For major changes, please open an issue first to discuss what
+you would like to change.
+
+## Acknowledgements
+
+Thanks to:
+
+- [@deanishe](https://github.com/deanishe) for
+ the [alfred-workflow](https://github.com/deanishe/alfred-workflow) library.
+- [@NorthIsUp](https://github.com/NorthIsUp) for updating it to Python 3
+ in [alfred-workflow-py3](https://github.com/NorthIsUp/alfred-workflow-py3).
+- [@kerma](https://github.com/kerma) for
+ the [defaultbrowser](https://github.com/kerma/defaultbrowser) tool which was a
+ valuable reference.
+
+## Security
+
+- [SECURITY.md](.github/SECURITY.md) (Security Policy)
+- [security.txt](.wellknown/security.txt) ([@securitytxt](https://github.com/securitytxt))
+
+## License
+
+[MIT](LICENSE)
diff --git a/__version__.py b/__version__.py
index 33ce711..0afd4be 100644
--- a/__version__.py
+++ b/__version__.py
@@ -1,4 +1,4 @@
-__version__ = "0.1.0"
+__version__ = "1.0.0"
if __name__ == "__main__":
print(__version__)
diff --git a/defaultbrowser.py b/defaultbrowser.py
index e69146d..5a3ad45 100644
--- a/defaultbrowser.py
+++ b/defaultbrowser.py
@@ -11,25 +11,42 @@
# setup access to the local lib directory
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)) + "/lib") # noqa
-import workflow
from workflow import Workflow3
+import objc
import CoreFoundation
from CoreServices import LaunchServices
def get_current_default_browser():
+ # In theory LSCopyDefaultRoleHandlerForContentType is deprecated
+ # https://developer.apple.com/documentation/coreservices/1449868-lscopydefaultrolehandlerforconte?language=objc
return LaunchServices.LSCopyDefaultRoleHandlerForContentType(
CoreFoundation.CFSTR("public.html"), LaunchServices.kLSRolesViewer
)
def get_browsers():
+ # In theory LSCopyAllRoleHandlersForContentType is deprecated
+ # https://developer.apple.com/documentation/coreservices/1448020-lscopyallrolehandlersforcontentt?language=objc
return LaunchServices.LSCopyAllRoleHandlersForContentType(
CoreFoundation.CFSTR("public.html"), LaunchServices.kLSRolesViewer
)
+def get_browser_url(bundle_id):
+ # https://developer.apple.com/documentation/coreservices/1449290-lscopyapplicationurlsforbundleid?language=objc
+ apps = LaunchServices.LSCopyApplicationURLsForBundleIdentifier(bundle_id, objc.NULL)
+ return apps[0][0]
+
+
+def get_browser_display_name(url):
+ name = url.lastPathComponent()
+ return name
+
+
def set_browser(browser: str):
+ # In theory LSSetDefaultHandlerForURLScheme is deprecated
+ # https://developer.apple.com/documentation/coreservices/1447760-lssetdefaulthandlerforurlscheme?language=objc
LaunchServices.LSSetDefaultHandlerForURLScheme(
CoreFoundation.CFSTR("http"), CoreFoundation.CFSTR(browser)
)
@@ -40,12 +57,35 @@ def main(wf: Workflow3):
current_default = get_current_default_browser()
browsers = get_browsers()
for browser in browsers:
+ url = get_browser_url(browser)
+ title = get_browser_display_name(url)
+ path = url.path()
+
if browser == current_default:
- wf.add_item(title=browser, icon=workflow.ICON_FAVOURITE, valid=False)
+ # Use a different uid when it is currently the default. This improves suggestions.
+ uid = f"current+{browser}"
+ subtitle = "Current default browser"
+ valid = False
+ arg = None
else:
- wf.add_item(
- title=browser, icon=workflow.ICON_WEB, valid=True, arg=browser
- )
+ uid = browser
+ subtitle = f"Set {title} as default browser"
+ valid = True
+ arg = browser
+
+ wf.add_item(
+ uid=uid,
+ title=title,
+ subtitle=subtitle,
+ icon=path,
+ icontype="fileicon",
+ valid=valid,
+ arg=arg,
+ autocomplete=title,
+ copytext=path,
+ largetext=title,
+ quicklookurl=url.path(),
+ )
wf.send_feedback()
except Exception as e:
diff --git a/icon.png b/icon.png
index 4975a05..0e6ed8c 100644
Binary files a/icon.png and b/icon.png differ
diff --git a/info.plist b/info.plist
index a5ee197..fff7682 100644
--- a/info.plist
+++ b/info.plist
@@ -61,13 +61,13 @@
alfredfiltersresultsalfredfiltersresultsmatchmode
- 0
+ 2argumenttreatemptyqueryasnilargumenttrimmode0argumenttype
- 2
+ 1escaping102keyword
@@ -95,7 +95,7 @@
type5withspace
-
+ typealfred.workflow.input.scriptfilter
@@ -108,13 +108,33 @@
readme# Py3 Default Browser
-This workflow makes it simple to change your default browser from alfred. The default shortcut is 'db' and you can then pick a browser from the list of available options. macOS requires you to confirm the change in a pop up dialog.
+ This Alfred workflow makes it simple to change your default browser on macOS.
+
+ ## Usage
+
+ The default shortcut is `db` and you can then pick a browser from the list of available options. macOS requires
+ you to confirm the change in a pop up dialog.
+
+ ## Support
+
+ If you have any questions or feature requests then please file an Issue on GitHub
+ https://github.com/wmorland/alfred-py3-default-browser/issues/new or reach out to me on Twitter, @w_morland.
+
+ ## Acknowledgements
+
+ Thanks to:
-## Acknowledgements
+ - [@deanishe](https://github.com/deanishe) for the
+ [alfred-workflow](https://github.com/deanishe/alfred-workflow) library.
+ - [@NorthIsUp](https://github.com/NorthIsUp) for updating it to Python 3 in
+ [alfred-workflow-py3](https://github.com/NorthIsUp/alfred-workflow-py3).
+ - [@kerma](https://github.com/kerma) for the [defaultbrowser](https://github.com/kerma/defaultbrowser) tool
+ which was a valuable reference.
-Thank you to deanishe for the alfred-workflow library and NorthIsUp for updating it to Python 3.
+ ## License
-Thank you to kerma for their work on the defaultbrowser tool which was a valuable reference.
+ [MIT](LICENSE)
+
uidata50210409-4BFA-45C8-A76D-E6983E3001C2
@@ -122,7 +142,7 @@ Thank you to kerma for their work on the defaultbrowser tool which was a valuabl
noteThis runs the action to set the chosen browser as default. The user will still have to manually confirm their choice.xpos
- 450
+ 625ypos100
@@ -136,11 +156,9 @@ Thank you to kerma for their work on the defaultbrowser tool which was a valuabl
100
- variablesdontexport
- version
- 0.1.0
+ 1.0.0webaddress
- https://github.com/wmorland
+ https://github.com/wmorland/alfred-py3-default-browser