Created
March 19, 2016 05:12
-
-
Save xtetsuji/0ed5a7440883160d9e03 to your computer and use it in GitHub Desktop.
JXA frontend
This file contains hidden or 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
#!/bin/bash | |
ARG1="$1" | |
shift | |
JSRUN="osascript -l JavaScript" | |
COMMAND_LIST="gcal|chrome_tabs|round_tabs" | |
function dispatch_gcal { | |
$JSRUN <<EOF | |
app = Application("Google Chrome") | |
win = app.windows[0]; | |
tabindex = 1; | |
win.tabs().forEach(function(tab){ | |
if ( tab.url().match(/^https?:\/\/calendar\.google\.com\//) ) { | |
win.activeTabIndex = tabindex; | |
app.activate(); | |
return true; | |
} | |
tabindex++; | |
}); | |
EOF | |
} | |
function dispatch_chrome_tabs { | |
$JSRUN <<EOF | |
app = Application("Google Chrome"); | |
wincount = 0; | |
app.windows().forEach(function(win){ | |
console.log("=== window " + (wincount++) + " ==="); | |
tabcount = 0; | |
win.tabs().forEach(function(tab){ | |
console.log((tabcount++).toString() + ": " + tab.url()); | |
}) | |
}) | |
EOF | |
} | |
function dispatch_round_tabs { | |
local DELAY="${1:-0.5}" | |
$JSRUN <<EOF | |
const DELAY = ${DELAY}; | |
app = Application("Google Chrome"); | |
app.activate(); | |
win = app.windows[0]; | |
tab_length = win.tabs().length; | |
console.log("tab_length="+tab_length); | |
for(current_tab_index = 1; current_tab_index <= tab_length; current_tab_index++) { | |
win.activeTabIndex = current_tab_index; | |
delay(DELAY); | |
} | |
EOF | |
} | |
if type "dispatch_$ARG1" &>/dev/null ; then | |
dispatch_$ARG1 "$@" 2>&1 | |
else | |
echo "Usage:" | |
echo " $(basename $0) [$COMMAND_LIST]" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment