Skip to content

Instantly share code, notes, and snippets.

@phansch
Created May 17, 2017 15:27
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 phansch/a8b795b74edbaa6f9fb05ea65b3068cf to your computer and use it in GitHub Desktop.
Save phansch/a8b795b74edbaa6f9fb05ea65b3068cf to your computer and use it in GitHub Desktop.
Upload the latest screenshot to s3 and copy the URL to the clipboard using xclip
#!/usr/bin/ruby
bucket_name = 's3_bucket_name'
region = 's3_region'
images_dir = "#{Dir.home}/Pictures/screenshots/*"
newest_file = Dir.glob(images_dir).max_by { |f| File.mtime(f) }
filename = File.basename(newest_file)
cmd = "aws s3 cp #{newest_file} s3://#{bucket_name}/#{filename} --region #{region} --acl public-read"
s3_url = "https://#{bucket_name}.s3.amazonaws.com/#{filename}"
IO.popen('xclip', 'w') do |io|
io.print(s3_url)
end
puts `#{cmd}`
puts 'File uploaded to S3 and link copied to clipboard:'
puts s3_url
@phansch
Copy link
Author

phansch commented May 17, 2017

This could probably use some error handling or xclip/xsel/pbcopy detection, but it works for me right now :shipit:

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