Skip to content

Instantly share code, notes, and snippets.

@pesla
Last active October 22, 2015 13:14
Show Gist options
  • Save pesla/6ed38b2fd17b1bfdf515 to your computer and use it in GitHub Desktop.
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 Canary"
if (count every window) > 0 then
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
set query to "zds = document.querySelector('.zd-searchmenu .zd-searchmenu-base'); if (zds) { zds.value = '" & ticketId & "'; zde = window.jQuery.Event('keydown'); zde.keyCode = 13; window.jQuery(zds).trigger(zde); }" as text
tell theTab to set URL to "javascript:" & query
set theWindow's active tab index to theTabIndex
set winTitle to name of theWindow
activate
tell application "System Events"
tell process "Google Chrome Canary"
tell menu bar 1
click menu item winTitle of menu 1 of menu bar item -2
end tell
end tell
end tell
end if
end if
end tell
if not found then
tell application "Google Chrome Canary"
if (count every window) = 0 then
make new window
end if
tell window 1 to make new tab with properties {URL:serverURI & browserURL}
activate
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