Skip to content

Instantly share code, notes, and snippets.

@jpillora
Created February 7, 2021 06:47
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpillora/702ded79330043e38e8202b5c73835e5 to your computer and use it in GitHub Desktop.
Save jpillora/702ded79330043e38e8202b5c73835e5 to your computer and use it in GitHub Desktop.
Download iCloud link from Terminal
#!/bin/bash
# given "https://www.icloud.com/iclouddrive/<ID>#<Filename>
ID="...."
URL=$(curl 'https://ckdatabasews.icloud.com/database/1/com.apple.cloudkit/production/public/records/resolve' \
--data-raw '{"shortGUIDs":[{"value":"$ID"}]}' --compressed \
jq -r '.results[0].rootRecord.fields.fileContent.value.downloadURL')
curl "$URL" -o myfile.ext
@philippwulff
Copy link

philippwulff commented Mar 15, 2023

Running

export URL=$(curl 'https://ckdatabasews.icloud.com/database/1/com.apple.cloudkit/production/public/records/resolve' \
   --data-raw '{"shortGUIDs":[{"value":"$ID"}]}' --compressed \
   jq -r '.results[0].rootRecord.fields.fileContent.value.downloadURL')

gives me

Warning: Invalid character is found in given range. A specified range MUST 
Warning: have only digits in 'start'-'stop'. The server's response to this 
Warning: request is uncertain.
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   195    0   163  100    32    573    112 --:--:-- --:--:-- --:--:--   684
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: jq

Edit:

So I needed to change the \ to a | like this:

export URL=$(curl 'https://ckdatabasews.icloud.com/database/1/com.apple.cloudkit/production/public/records/resolve' \
  --data-raw '{"shortGUIDs":[{"value":"$ID"}]}' --compressed |
  jq -r '.results[0].rootRecord.fields.fileContent.value.downloadURL')

but now echo $URL gives me

(base) wulff@VC02:/home/shared$ echo $URL
null

@poa00
Copy link

poa00 commented Apr 2, 2024

Does this work for shared icloud folders?

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