forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault-browser-front-most-app.applescript
executable file
·102 lines (86 loc) · 3.33 KB
/
default-browser-front-most-app.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/osascript
# Dependency: requires defaultbrowser (https://github.com/kerma/defaultbrowser/)
# Install via Homebrew: `brew install defaultbrowser`
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Set Frontmost App as Default Browser
# @raycast.mode silent
# Browser dev is developer version of Google Chrome
# @raycast.argument1 { "type": "text", "placeholder": "Browser (chrome, dev, safari, firefox)", "optional": true }
# Optional parameters:
# @raycast.packageName Browsing
# @raycast.icon 🧭
# Documentation:
# @raycast.author Yohanes Bandung Bondowoso
# @raycast.authorURL https://github.com/ybbond
# @raycast.description Set Frontmost Web Browser as Default Browser.
# raycastArgv is Raycast argument
on run {raycastArgv}
if (raycastArgv is equal to "") then
tell application "System Events"
tell (first process whose frontmost is true)
set appName to displayed name
end tell
end tell
set browserName to appName
if (appName contains "Brave Browser") then
set browserName to "browser"
else if (appName is equal to "Safari") then
set browserName to "safari"
else if (appName is equal to "Safari Technology Preview") then
set browserName to "safaritechnologypreview"
# set Google chrome dev as default browser
# it need to put before Chrome
else if (appName contains "dev") then
set browserName to "dev"
else if (appName contains "Chrome") then
set browserName to "chrome"
else if (appName is equal to "Chromium") then
set browserName to "chromium"
else if (appName is equal to "Firefox") then
set browserName to "firefox"
else if (appName is equal to "Firefox Developer Edition") then
set browserName to "firefoxdeveloperedition"
end if
else
# appName is used for print log message
if (raycastArgv is equal to "dev")
set appName to "Chrome dev"
else
set appName to raycastArgv
end if
set browserName to raycastArgv
end if
# display dialog ("Set defaut browser is " & raycastArgv & "!")
try
set commandResult to do shell script "defaultbrowser" & space & browserName & space & "2>/dev/null "
if (commandResult contains "The command exited with a non-zero status") then
log "Shell command 'defaultbrowser' is required."
else if (commandResult contains "is already set as the default HTTP handler" or commandResult is equal to "") then
log appName & space & "already set as default browser"
else if (commandResult contains "is not available as an HTTP handler") then
log appName & space & "is not a web browser, or not handled yet :("
end if
on error errStr
set commandResult to errStr
if (commandResult contains "The command exited with a non-zero status") then
log "Shell command 'defaultbrowser' is required."
else if (commandResult contains "is already set as the default HTTP handler" or commandResult is equal to "") then
log appName & space & "already set as default browser"
else if (commandResult contains "is not available as an HTTP handler") then
log appName & space & "is not a web browser, or not handled yet :("
end if
end try
try
tell application "System Events"
tell application process "CoreServicesUIAgent"
tell window 1
tell (first button whose name starts with "use")
perform action "AXPress"
log appName & space & "set as default browser"
end tell
end tell
end tell
end tell
end try
end run