Last active
January 20, 2019 13:42
-
-
Save blindFS/39a148d7634e3a9099fce6f6755fbeec to your computer and use it in GitHub Desktop.
Hammerspoon HSearch mod
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
local function openWithSafari(arg) | |
hs.osascript.applescript('tell window ' .. arg[1] .. ' of application "Safari"\nset current tab to tab ' .. arg[2] .. '\nactivate\nend tell') | |
end | |
local function openWithChrome(arg) | |
hs.osascript.applescript('tell application "Google Chrome"\nrepeat with win in windows\nif id of win = ' .. arg[1] .. ' then\nset active tab index of win to ' .. arg[2] .. '\nset index of win to 1\nend if\nend repeat\ndelay 0.1\ndo shell script "open -a Google\\\\ Chrome"\nend tell') | |
end | |
-- hs_btabs.lua | |
local function browserTabsRequest() | |
local safari_running = hs.application.applicationsForBundleID("com.apple.Safari") | |
local chooser_data = {} | |
if #safari_running > 0 then | |
local stat, data= hs.osascript.applescript('tell application "Safari"\nset tablist to {}\nrepeat with win in windows\nrepeat with n from 1 to count of tabs of win\nset currenttab to item n of tabs of win\nset tabinfo to {index of win, n, name of currenttab as Unicode text, URL of currenttab}\ncopy tabinfo to the end of tablist\nend repeat\nend repeat\nreturn tablist\nend tell') | |
-- Notice `output` key and its `arg`. The built-in output contains `browser`, `safari`, `chrome`, `firefon`, `clipboard`, `keystrokes`. You can define new output type if you like. | |
if stat then | |
chooser_data = hs.fnutils.imap(data, function(item) | |
return {text=item[3], subText=item[4], image=hs.image.imageFromPath(obj.spoonPath .. "/resources/safari.png"), output="safari", arg={item[1], item[2]}} | |
end) | |
end | |
end | |
local chrome_running = hs.application.applicationsForBundleID("com.google.Chrome") | |
if #chrome_running > 0 then | |
local stat, data= hs.osascript.applescript('tell application "Google Chrome"\nset tablist to {}\nrepeat with win in windows\nrepeat with n from 1 to count of tabs of win\nset currenttab to item n of tabs of win\nset tabinfo to {id of win, n, title of currenttab as Unicode text, URL of currenttab}\ncopy tabinfo to the end of tablist\nend repeat\nend repeat\nreturn tablist\nend tell') | |
if stat then | |
for idx,val in pairs(data) do | |
-- Usually we want to open chrome tabs in Google Chrome. | |
table.insert(chooser_data, {text=val[3], subText=val[4], image=hs.image.imageFromPath(obj.spoonPath .. "/resources/chrome.png"), output="chrome", arg={val[1], val[2]}}) | |
end | |
end | |
end | |
-- Return specific table as hs.chooser's data, other keys except for `text` could be optional. | |
return chooser_data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment