Skip to content

Instantly share code, notes, and snippets.

@erikhansen
Last active July 28, 2023 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikhansen/bc645d16d8f97eaf9a807070e475a4d6 to your computer and use it in GitHub Desktop.
Save erikhansen/bc645d16d8f97eaf9a807070e475a4d6 to your computer and use it in GitHub Desktop.
MacOS Automator Script to export list of on-premise Jira issues to PDF

Instructions

This document covers how to export Jira tickets to PDF from the on-premise version of Jira. For the cloud version of Jira, you can write a script to download Word versions of each issue (e.g., https://krakencommerce.atlassian.net/si/jira.issueviews:issue-word/DMC-95/DMC-95.doc) and you don't need this approach.

  1. Prepare a text file containing all urls of the Jira issues you want to export. For example:
https://krakencommerce.atlassian.net/browse/DMC-1
https://krakencommerce.atlassian.net/browse/DMC-2
…
https://krakencommerce.atlassian.net/browse/DMC-95
  1. Login to Jira in Google Chrome
  2. In Google Chrome, select View > Developer > Allow JavaScript from Apple Events
  3. Open a single Jira issue in Chrome, click File > Print…, select Save as PDF and then click Save. This will set PDF as the default print output, which is necessary for the automation to work.
  4. Open the Automator app.
  5. Create a new Workflow and the select Run AppleScript Untitled 2023-07-27 20-58-51
  6. Paste the contents of the download_jira_issues.scpt file below into the app.
  7. Click the Run icon
  8. Select the text file you selected in step one
  9. Leave your computer running for as long as it takes to print all issues to PDF
on run {input, parameters}
-- To test with a single url, uncomment this line and comment out 2 lines below it
-- set theURLs to {"https://krakencommerce.atlassian.net/browse/DMC-95"}
set theFile to choose file with prompt "Please select your file:"
set theURLs to read theFile as «class utf8» using delimiter linefeed
repeat with theURL in theURLs
tell application "Google Chrome"
open location theURL
-- Delay to allow page to load fully
delay 5
activate
-- Open developer console to be able to observe if there are any console errors
tell application "System Events"
keystroke "i" using {command down, option down}
delay 1
end tell
tell active tab of window 1
-- Click "Show more comments" button to load all comments
execute javascript "var elem = document.querySelector('a.collapsed-comments.show-more-comments.aui-button'); if (elem) elem.click();"
--- For all image attachments, replace low quality image with high quality image
execute javascript "document.querySelectorAll('.attachment-thumb').forEach(item => { var a = item.querySelector('a'); var img = item.querySelector('img'); if (a && img) img.setAttribute('src', a.getAttribute('href')); });"
--- For all attachments that are not images, open attachment so that the attachment is downloaded
execute javascript "document.querySelectorAll('.attachment-thumb').forEach(item => { if (item.querySelector('a > span')) { window.location.href = item.querySelector('a').getAttribute('href'); }});"
-- Delay to allow assets to load
delay 5
end tell
-- Close developer console
tell application "System Events"
keystroke "i" using {command down, option down}
delay 0.5
end tell
end tell
tell application "System Events"
-- Open print dialog
keystroke "p" using {command down}
delay 1
keystroke return
delay 1
keystroke return
delay 2
-- tab character
keystroke (ASCII character 9)
delay 0.1
-- Space character
key code 49
delay 1.5
-- Close new browser tab
keystroke "w" using {command down}
delay 0.1
end tell
end repeat
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment