Skip to content

Instantly share code, notes, and snippets.

@jonkwheeler
Last active August 30, 2023 15:41
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jonkwheeler/c1a9669d4d203c84b5085062e49863f5 to your computer and use it in GitHub Desktop.
Save jonkwheeler/c1a9669d4d203c84b5085062e49863f5 to your computer and use it in GitHub Desktop.
Download Slack Profile Pictures / Images
// Enter slack in the browser. https://{insert your team name here}.slack.com/messages/
// Click on the channel you want.
// Click the information icon.
// Expand the members dropdown.
// Click "See All Members"
// Paste the next line into the console, hit enter.
var imageList = new Array()
// If your channel has more than 19 members, the list won't display past that. It also unloads them from the state as you scroll.
// Paste the following section into the console, hit enter.
var $slackUser = $('#channel_membership_dialog_scroller').find('.member_item')
$slackUser.each(function(i, e) {
var $this = $(this)
var $memberImageElem = $this.find('.member_image')
var $memberThumbnail = $memberImageElem.css('background-image')
var $memberThumbnailUrl = $memberThumbnail
.replace('url("', '')
.replace('-24")', '-500')
imageList.push($memberThumbnailUrl)
})
// If your list is over 19 members, you'll have to drag the list scrollbar down to force a state update of member. Run the above script again (lines 13-22).
// Repeat this until you've gone through the whole list. It's okay if you get duplicates.
// After your list is done, paste into terminal, hit enter.
copy(imageList)
// Open editor, paste newly copied imageList from console into a new file, save as imagelist.txt
// Remove all quotes, commas, and brackets so urls are on one line a piece (a quick find/replace works)
// In terminal run the following:
xargs -n 1 curl -O < imagelist.txt
// The images should start to download. It will merge duplicates.
// You'll need to mass file rename this to add `.jpg` as an extension.
@Jamedjo
Copy link

Jamedjo commented Feb 22, 2023

For the 2023 members list dialog I adapted this to the following:

var $slackUsersImages = document.querySelectorAll('[aria-label="Members in channel"] [data-qa="member-entity__avatar"] img')
$slackUsersImages.forEach(function(el,i) {
	var $memberThumbnail = el.src
	var $memberThumbnailUrl = $memberThumbnail
		.replace('url("', '')
		.replace('-48', '-500')
	imageList.push($memberThumbnailUrl)
})

To download I then used copy([...new Set(imageList)] to get uniq items only and wl-paste | jq -c '.[]' | xargs -n 1 wget to download

@caseywatts
Copy link

Thank you for this!!

After wrestling with the Slack API and trying to make a Slack App just so I could run a script...
...this web scraping approach is a breath of fresh air! 👏

I updated this script in a few ways:

  • duplicate entries are automatically removed (thanks to "Map"!)
  • scrolling auto-adds entries to the list
  • name files after each person's name
  • copy-paste a list of curl commands directly; no file needed

My updated version:
https://gist.github.com/caseywatts/24e9c76de72692a51955f23e39137221

@jonkwheeler
Copy link
Author

I'm surprised it even still works. A 5.5 year old script. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment