Created
April 22, 2025 09:14
-
-
Save htlin222/d42baa4cd2b569092f6caea4163b6f87 to your computer and use it in GitHub Desktop.
This Bash function icloudownload forces iCloud files or folders to download locally on macOS by reading the first byte of each file, which triggers iCloud sync. It supports both single files and entire directories, displaying progress and file size during the process.
This file contains hidden or 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
function icloudownload() { | |
if ! command -v find >/dev/null; then | |
echo "❌ 'find' is not installed. Please install it first." | |
return 1 | |
fi | |
if [[ -z "$1" ]]; then | |
echo "📂 Usage: icloudownload /path/to/icloud/file_or_folder" | |
return 1 | |
fi | |
local target="$1" | |
if [[ -f "$target" ]]; then | |
local size=$(stat -f%z "$target") | |
echo -ne "📄 [1/1] Processing: $target (${size} bytes) \r" | |
head -c 1 "$target" > /dev/null | |
echo -e "✅ Done: $target (${size} bytes) " | |
elif [[ -d "$target" ]]; then | |
# 正確抓取檔案名,支援空白路徑 | |
local IFS=$'\n' | |
local files=($(find "$target" -type f)) | |
local total=${#files[@]} | |
local count=0 | |
for file in "${files[@]}"; do | |
((count++)) | |
local size=$(stat -f%z "$file") | |
echo -ne "📄 [$count/$total] Processing: $file (${size} bytes) \r" | |
head -c 1 "$file" > /dev/null | |
done | |
echo -e "\n✅ Folder download complete: $target ($total files)" | |
else | |
echo "❌ '$target' is not a valid file or folder." | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage