Last active
October 22, 2015 13:14
-
-
Save pesla/6ed38b2fd17b1bfdf515 to your computer and use it in GitHub Desktop.
Open ticket in Zendesk from Alfred (workflow)
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
| 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 | |
| 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 & "/agent" then | |
| set found to true | |
| exit repeat | |
| end if | |
| end repeat | |
| if found then | |
| exit repeat | |
| end if | |
| end repeat | |
| if found then | |
| activate | |
| tell theTab | |
| execute javascript " | |
| (function() { | |
| function fireKeyDownEventWithKeyCode(element, keyCode) { | |
| var oEvent = document.createEvent('KeyboardEvent'); | |
| // Chromium Hack | |
| Object.defineProperty(oEvent, 'keyCode', { | |
| get : function() { | |
| return this.keyCodeVal; | |
| } | |
| }); | |
| Object.defineProperty(oEvent, 'which', { | |
| get : function() { | |
| return this.keyCodeVal; | |
| } | |
| }); | |
| if (oEvent.initKeyboardEvent) { | |
| oEvent.initKeyboardEvent('keydown', true, true, document.defaultView, false, false, false, false, keyCode, keyCode); | |
| } else { | |
| oEvent.initKeyEvent('keydown', true, true, document.defaultView, false, false, false, false, keyCode, 0); | |
| } | |
| oEvent.keyCodeVal = keyCode; | |
| if (oEvent.keyCode !== keyCode) { | |
| console && console.log('keyCode mismatch ' + oEvent.keyCode + '(' + oEvent.which + ')'); | |
| } | |
| element.dispatchEvent(oEvent); | |
| } | |
| var searchBar = document.querySelector('.header-search input'); | |
| if (!searchBar) { | |
| return; | |
| } | |
| searchBar.value = " & ticketId & "; | |
| fireKeyDownEventWithKeyCode(searchBar, 13); | |
| })(); | |
| " | |
| end tell | |
| set theWindow's active tab index to theTabIndex | |
| set index of theWindow to 1 | |
| end if | |
| end if | |
| end tell | |
| if not found then | |
| tell application "Google Chrome Canary" | |
| activate | |
| if (count every window) = 0 then | |
| make new window | |
| end if | |
| tell window 1 to make new tab with properties {URL:serverURI & 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