generated from Wox-launcher/Wox.Plugin.Template.Nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03a2411
commit e473c21
Showing
8 changed files
with
329 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
# Wox.Plugin.Template.Nodejs | ||
# Wox.Plugin.Arc | ||
|
||
Plugin template for nodejs plugin | ||
A Wox plugin to search tabs of arc browser (only support macos). | ||
|
||
# How to Install | ||
|
||
Run `wpm install arc` in Wox. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
{ | ||
"Id": "[Id]", | ||
"Id": "84cb8c8f-1156-489d-a490-6d04fbc85d52", | ||
"TriggerKeywords": [ | ||
"[Trigger Keyword]" | ||
"*", | ||
"arc" | ||
], | ||
"Name": "[Name]", | ||
"Description": "[Description]", | ||
"Author": "[Author Name]", | ||
"Name": "Arc", | ||
"Description": "Search arc tabs and spaces", | ||
"Author": "Wox-team", | ||
"Version": "0.0.1", | ||
"MinWoxVersion": "2.0.0", | ||
"Runtime": "[Runtime]", | ||
"Website": "[Website]", | ||
"Runtime": "nodejs", | ||
"Website": "https://github.com/Wox-launcher/Wox.Plugin.Arc", | ||
"Entry": "index.js", | ||
"Icon": "relative:images/app.png", | ||
"SupportedOS": [ | ||
"windows", | ||
"linux", | ||
"darwin" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,226 @@ | ||
// Source: https://github.com/raycast/extensions/tree/94a85235fc605b1ad5eb75ff13bb3fad742b4b07/extensions/arc/ | ||
|
||
import { runAppleScript } from "run-applescript" | ||
import { Space, Tab } from "./types.js" | ||
|
||
export async function getTabs() { | ||
const response = await runAppleScript(` | ||
on escape_value(this_text) | ||
set AppleScript's text item delimiters to the "\\"" | ||
set the item_list to every text item of this_text | ||
set AppleScript's text item delimiters to the "\\\\\\"" | ||
set this_text to the item_list as string | ||
set AppleScript's text item delimiters to "" | ||
return this_text | ||
end replace_chars | ||
set _output to "" | ||
tell application "Arc" | ||
set _window_index to 1 | ||
set _tab_index to 1 | ||
repeat with _tab in tabs of first window | ||
set _title to my escape_value(get title of _tab) | ||
set _url to get URL of _tab | ||
set _location to get location of _tab | ||
set _output to (_output & "{ \\"title\\": \\"" & _title & "\\", \\"url\\": \\"" & _url & "\\", \\"windowId\\": " & _window_index & ", \\"tabId\\": " & _tab_index & " , \\"location\\": \\"" & _location & "\\" }") | ||
if _tab_index < (count tabs of first window) then | ||
set _output to (_output & ",\\n") | ||
else | ||
set _output to (_output & "\\n") | ||
end if | ||
set _tab_index to _tab_index + 1 | ||
end repeat | ||
end tell | ||
return "[\\n" & _output & "\\n]" | ||
`) | ||
|
||
return response ? (JSON.parse(response) as Tab[]) : undefined | ||
} | ||
|
||
export async function findTab(url: string) { | ||
const response = await runAppleScript(` | ||
on escape_value(this_text) | ||
set AppleScript's text item delimiters to the "\\"" | ||
set the item_list to every text item of this_text | ||
set AppleScript's text item delimiters to the "\\\\\\"" | ||
set this_text to the item_list as string | ||
set AppleScript's text item delimiters to "" | ||
return this_text | ||
end replace_chars | ||
set _output to "" | ||
tell application "Arc" | ||
set _window_index to 1 | ||
repeat with _window in windows | ||
set _tab_index to 1 | ||
repeat with _tab in tabs of _window | ||
set _url to get URL of _tab | ||
if _url is equal "${url}" then | ||
set _title to my escape_value(get title of _tab) | ||
set _location to get location of _tab | ||
set _output to (_output & "{ \\"title\\": \\"" & _title & "\\", \\"url\\": \\"" & _url & "\\", \\"windowId\\": " & _window_index & ", \\"tabId\\": " & _tab_index & " , \\"location\\": \\"" & _location & "\\" }") | ||
return _output | ||
end if | ||
set _tab_index to _tab_index + 1 | ||
end repeat | ||
set _window_index to _window_index + 1 | ||
end repeat | ||
end tell | ||
return _output | ||
`) | ||
|
||
return response ? (JSON.parse(response) as Tab) : undefined | ||
} | ||
|
||
export async function selectTab({ windowId, tabId }: Pick<Tab, "windowId" | "tabId">) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
tell window (${windowId} as number) | ||
tell tab (${tabId} as number) to select | ||
end tell | ||
activate | ||
end tell | ||
`) | ||
} | ||
|
||
export async function closeTab({ windowId, tabId }: Pick<Tab, "windowId" | "tabId">) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
tell window (${windowId} as number) | ||
tell tab (${tabId} as number) to close | ||
end tell | ||
end tell | ||
`) | ||
} | ||
|
||
export async function reloadTab({ windowId, tabId }: Pick<Tab, "windowId" | "tabId">) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
tell window (${windowId} as number) | ||
tell tab (${tabId} as number) to reload | ||
end tell | ||
end tell | ||
`) | ||
} | ||
|
||
export async function makeNewTab(url: string) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
tell front window | ||
make new tab with properties {URL:"${url}"} | ||
end tell | ||
activate | ||
end tell | ||
`) | ||
} | ||
|
||
export type MakeNewWindowOptions = { | ||
incognito?: boolean; | ||
url?: string; | ||
}; | ||
|
||
export async function makeNewWindow(options: MakeNewWindowOptions = {}): Promise<void> { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
make new window with properties {incognito:${options.incognito ?? false}} | ||
activate | ||
${ | ||
options.url | ||
? `tell front window to make new tab with properties {URL:"${options.url}"}` | ||
: "" | ||
} | ||
end tell | ||
`) | ||
} | ||
|
||
export async function makeNewLittleArcWindow(url: string) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
make new tab with properties {URL:"${url}"} | ||
activate | ||
end tell | ||
`) | ||
} | ||
|
||
export async function makeNewTabWithinSpace(url: string, space: Space) { | ||
await runAppleScript(` | ||
tell application "Arc" | ||
tell front window | ||
tell space ${space.id} | ||
make new tab with properties {URL:"${url}"} | ||
end tell | ||
end tell | ||
activate | ||
end tell | ||
`) | ||
} | ||
|
||
export async function selectSpace(id: Space["id"]) { | ||
await runAppleScript(` | ||
launch app "Arc" | ||
delay "1" | ||
tell application "Arc" | ||
tell front window | ||
tell space ${id} to focus | ||
end tell | ||
end tell | ||
`) | ||
} | ||
|
||
export async function getSpaces() { | ||
const response = await runAppleScript(` | ||
set _output to "" | ||
tell application "Arc" | ||
set _space_index to 1 | ||
repeat with _space in spaces of front window | ||
set _title to get title of _space | ||
set _output to (_output & "{ \\"title\\": \\"" & _title & "\\", \\"id\\": " & _space_index & " }") | ||
if _space_index < (count spaces of front window) then | ||
set _output to (_output & ",\\n") | ||
else | ||
set _output to (_output & "\\n") | ||
end if | ||
set _space_index to _space_index + 1 | ||
end repeat | ||
end tell | ||
return "[\\n" & _output & "\\n]" | ||
`) | ||
|
||
return response ? (JSON.parse(response) as Space[]) : undefined | ||
} | ||
|
||
export async function getVersion() { | ||
const response = await runAppleScript(` | ||
tell application "Arc" | ||
return version | ||
end tell | ||
`) | ||
|
||
return response | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.