forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscreenshot-and-imgur.sh
executable file
·51 lines (42 loc) · 1.52 KB
/
screenshot-and-imgur.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Screenshot and Imgur
# @raycast.mode silent
# @raycast.packageName Opens Screenshot Interface and Uploads
#
# Optional parameters:
# @raycast.icon 📷
#
# Documentation:
# @raycast.description Opens default screenshot interface and immediately uploads and copies link to clipboard
# @raycast.author Fahim Faisal
# @raycast.authorURL https://github.com/i3p9
#Client ID, use your own client ID. Get it from https://api.imgur.com/oauth2/addclient (Select anonymous usage as auth type)
client_id="" #CAN NOT BE EMPTY
if [ "$client_id" == "" ]; then
echo "No API Key found. Configure your own key before running"
exit -1
fi
function upload {
curl --location --request POST 'https://api.imgur.com/3/image' --header "Authorization: Client-ID $client_id" --form "image=$1"
}
#Opens screenshot interface
screencapture -c -s
#Grabs the screenshot from clipboard into a png file, uploads
clip_img="$(mktemp).png"
pngpaste "${clip_img}"
output=$(upload "@$clip_img") 2>/dev/null
#Parse response from Imgur
if echo "$output" | grep -q 'success="0"'; then
echo "From Imgur: Upload Error, try again" >&2
elif echo "$output" | grep -q 'Imgur is over capacity!'; then
echo "From Imgur: Upload Error, try again" >&2
else
url="${output##*\"link\":\"}"
url="${url%%\"\}*}"
delete_hash="${output##*<deletehash>}"
delete_hash="${delete_hash%%</deletehash>*}"
echo -n "$url" | pbcopy
echo "Screenshotted and Uploaded, Image link copied to clipboard"
fi