Created
May 17, 2017 15:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This could probably use some error handling or xclip/xsel/pbcopy detection, but it works for me right now