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.

Revisions

  1. pesla revised this gist Oct 22, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion open-ticket-from-alfred.zendesk.as
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ on alfred_script(q)
    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('#mn_1').trigger(zde); }" as text
    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
  2. pesla revised this gist Oct 22, 2015. 1 changed file with 2 additions and 48 deletions.
    50 changes: 2 additions & 48 deletions open-ticket-from-alfred.zendesk.as
    Original file line number Diff line number Diff line change
    @@ -22,57 +22,11 @@ on alfred_script(q)
    end repeat

    if found then
    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 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('#mn_1').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
  3. pesla revised this gist Oct 21, 2015. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions open-ticket-from-alfred.zendesk.as
    Original file line number Diff line number Diff line change
    @@ -1,18 +1,16 @@
    on alfred_script(q)
    set ticketId to q
    set serverURI to "https://procurios.zendesk.com"
    set browserURL to "tickets/" & ticketId
    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
    if URL of theTab starts with serverURI then
    set found to true
    exit repeat
    end if
    @@ -24,7 +22,6 @@ on alfred_script(q)
    end repeat

    if found then
    activate
    tell theTab
    execute javascript "
    (function() {
    @@ -70,21 +67,31 @@ on alfred_script(q)
    })();
    "
    end tell

    set theWindow's active tab index to theTabIndex
    set index of theWindow to 1
    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"
    activate
    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
  4. pesla revised this gist Oct 21, 2015. 1 changed file with 88 additions and 51 deletions.
    139 changes: 88 additions & 51 deletions open-ticket-from-alfred.zendesk.as
    Original file line number Diff line number Diff line change
    @@ -1,53 +1,90 @@
    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 & "/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 goToTicket() {
    URI = '" & browserURL & "';
    if (Zd && Zd.Routes) {
    Zd.Routes.goToHashNow(URI);
    }
    } goToTicket();"
    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"
    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
    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
  5. pesla revised this gist Oct 21, 2014. 1 changed file with 12 additions and 13 deletions.
    25 changes: 12 additions & 13 deletions open-ticket-from-alfred.zendesk.as
    Original file line number Diff line number Diff line change
    @@ -3,52 +3,51 @@ on alfred_script(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
    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
    set theWindow's active tab index to theTabIndex
    set index of theWindow to 1
    tell theWindow's active tab
    tell theTab
    execute javascript "function goToTicket() {
    URI = '" & browserURL & "';
    if (Zd && Zd.Routes) {
    Zd.Routes.goToHashNow(URI);
    }
    } goToTicket();"
    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"
    activate
    if (count every window) = 0 then
    make new window
    end if
    tell window 1 to make new tab with properties {URL:browserURL}
    tell window 1 to make new tab with properties {URL:serverURI & browserURL}
    end tell
    end if
    end alfred_script
  6. pesla renamed this gist Oct 21, 2014. 1 changed file with 0 additions and 0 deletions.
  7. pesla created this gist Oct 21, 2014.
    54 changes: 54 additions & 0 deletions open-ticket-in-zendesk.as
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    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