Last active
May 15, 2023 14:10
-
-
Save halka/41f656e85143c314f457495ffa22e522 to your computer and use it in GitHub Desktop.
Post from MacOS Terminal to Bluesky
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
# require install `coreutils` | |
# run command from terminal `brew install coreutils` | |
# usage | |
# chmod +x ./terminal.sh | |
# ./terminal.sh Hello!!!!!!!!!!!!!!!! | |
HANDLE='YOUR_HANDLE' | |
DID_URL="https://bsky.social/xrpc/com.atproto.identity.resolveHandle" | |
export DID=$(curl -G -s \ | |
--data-urlencode "handle=$HANDLE" \ | |
"$DID_URL" | jq -r .did) | |
# Get an app password from here: https://staging.bsky.app/settings/app-passwords | |
export APP_PASSWORD= | |
# Get API key with the app password | |
API_KEY_URL='https://bsky.social/xrpc/com.atproto.server.createSession' | |
POST_DATA="{ \"identifier\": \"${DID}\", \"password\": \"${APP_PASSWORD}\" }" | |
export API_KEY=$(curl -s -X POST \ | |
-H 'Content-Type: application/json' \ | |
-d "$POST_DATA" \ | |
"$API_KEY_URL" | jq -r .accessJwt) | |
POST_FEED_URL='https://bsky.social/xrpc/com.atproto.repo.createRecord' | |
POST_DATETIME=$(gdate -u +%Y-%m-%dT%H:%M:%S.%3N)Z | |
POST_RECORD="{ \"collection\": \"app.bsky.feed.post\", \"repo\": \"${DID}\", \"record\": { \"text\": \"$1\", \"createdAt\": \"$POST_DATETIME\", \"\$type\": \"app.bsky.feed.post\" } }" | |
curl -# -O -X POST "$POST_FEED_URL"\ | |
-H "Authorization: Bearer ${API_KEY}" \ | |
-H 'Content-Type: application/json' \ | |
-d "$POST_RECORD" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment