Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@phansch 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