Skip to content

Instantly share code, notes, and snippets.

@dennis-best
Last active October 9, 2017 19:20
Show Gist options
  • Save dennis-best/ca1ca3d6f1d6016d2b447345aec9b471 to your computer and use it in GitHub Desktop.
Save dennis-best/ca1ca3d6f1d6016d2b447345aec9b471 to your computer and use it in GitHub Desktop.
Create a branch name from a Jira ticket
-- This script will copy a specially formatted version of the current Chrome tab to your clipboard. For example, if you are viewing Jira ticket in Chrome, "sig-435-add-icons-to-abm-filter-panel" or "[SIG-435] Add icons to ABM filter panel" can be copied to the clipboard.
-- How to use: Save to ~/Library/Scripts folder and enable the AppleScript menu (launch Applications/Script Editor and go to settings) or download FastScripts (for more features including add hot keys).
tell application "Google Chrome"
if not (exists window 1) then return
set theTitle to the title of active tab of window 1
tell application "System Events"
end tell
end tell
set theTabTitle to replace_chars(theTitle, " - JIRA", "")
set theTabTitle to replace_chars(theTabTitle, "]", "")
set theTabTitle to replace_chars(theTabTitle, "[", "")
set theTabTitle to replace_chars(theTabTitle, " [", "")
set theTabTitle to replace_chars(theTabTitle, " ", "-")
set theTabTitle to do shell script "echo " & theTabTitle & " | tr A-Z a-z"
set niceTabTitle to replace_chars(theTitle, " - JIRA", "")
set question to display dialog "Choose a format" buttons {niceTabTitle, theTabTitle, "Cancel"}
set answer to button returned of question
if answer is equal to "Cancel" then
return
else
set the clipboard to answer
end if
--display dialog answer & " copied to clipboard" buttons {"Yay!"}
on replace_chars(this_text, search_string, replacement_string)
set AppleScript's text item delimiters to the search_string
set the item_list to every text item of this_text
set AppleScript's text item delimiters to the replacement_string
set this_text to the item_list as string
set AppleScript's text item delimiters to ""
return this_text
end replace_chars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment