Skip to content

Instantly share code, notes, and snippets.

@pesla
Last active October 22, 2015 13:14
Show Gist options
  • Select an option

  • Save pesla/6ed38b2fd17b1bfdf515 to your computer and use it in GitHub Desktop.

Select an option

Save pesla/6ed38b2fd17b1bfdf515 to your computer and use it in GitHub Desktop.
Open ticket in Zendesk from Alfred (workflow)
on alfred_script(q)
set ticketId to q
set serverURI to "https://procurios.zendesk.com"
set browserURL to "#/tickets/" & ticketId
set found to false
tell application "Google Chrome"
if (count every window) > 0 then
set theTabIndex to -1
repeat with theWindow in every window
set theTabIndex to 0
repeat with theTab in every tab of theWindow
set theTabIndex to theTabIndex + 1
if URL of theTab starts with serverURI then
set found to true
exit repeat
end if
end repeat
if found then
exit repeat
end if
end repeat
if found then
activate
set theWindow's active tab index to theTabIndex
set index of theWindow to 1
tell theWindow's active tab
execute javascript "function goToTicket() {
URI = '" & browserURL & "';
if (Zd && Zd.Routes) {
Zd.Routes.goToHashNow(URI);
}
} goToTicket();"
end tell
end if
end if
end tell
if not found then
tell application "Google Chrome"
activate
if (count every window) = 0 then
make new window
end if
tell window 1 to make new tab with properties {URL:browserURL}
end tell
end if
end alfred_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment