├── README.md ├── README_ZH.md ├── device_id_mac.sh └── device_id_win.ps1 /README.md: -------------------------------------------------------------------------------- 1 | # Cursor Device ID Management Tool 2 | 3 | English | [简体中文](README_ZH.md) 4 | 5 | ## You Know What 6 | 7 | Too many free trial accounts used on this machine 8 | 9 | ## Tips 10 | 11 | **Close the Cursor editor before use.** 12 | 13 | > No Windows test machine is available, so only macOS execution scripts are provided. It is unknown whether the historical scripts are usable. 14 | 15 | ## macOS 16 | 17 | - Run 18 | 19 | ```bash 20 | curl -fsSL https://raw.githubusercontent.com/resetsix/cursor_device_id/refs/heads/main/device_id_mac.sh | bash 21 | ``` 22 | 23 | - Help 24 | 25 | ```bash 26 | curl -fsSL https://raw.githubusercontent.com/resetsix/cursor_device_id/refs/heads/main/device_id_mac.sh | bash -s -- --help 27 | ``` 28 | 29 | - Log 30 | 31 | `~/Library/Application Support/Cursor/User/globalStorage/update.log` 32 | 33 | > If you're looking for storage.json file location 34 | > 35 | > %APPDATA%\Cursor\User\globalStorage\storage.json 36 | > 37 | > ~/Library/Application Support/Cursor/User/globalStorage/storage.json 38 | 39 | ## Star History 40 | 41 | [![Star History Chart](https://api.star-history.com/svg?repos=resetsix/cursor_device_id&type=Date)](https://star-history.com/#resetsix/cursor_device_id&Date) 42 | 43 | ## Contributors 44 | 45 | Welcome to join us and contribute code to cursor_device_id together. 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /README_ZH.md: -------------------------------------------------------------------------------- 1 | # Cursor 设备标识管理工具 2 | 3 | [English](README.md) | 简体中文 4 | 5 | ## 你知道的 6 | 7 | Too many free trial accounts used on this machine 8 | 9 | ## 提示 10 | 11 | **使用前关闭 Cursor 编辑器。** 12 | 13 | > 没有Windows测试机,所以只提供 macOS 执行脚本,历史脚本不知是否可用。 14 | 15 | ## macOS 16 | 17 | - 运行 18 | 19 | ```bash 20 | curl -fsSL https://raw.githubusercontent.com/resetsix/cursor_device_id/refs/heads/main/device_id_mac.sh | bash 21 | ``` 22 | 23 | - 帮助 24 | 25 | ```bash 26 | curl -fsSL https://raw.githubusercontent.com/resetsix/cursor_device_id/refs/heads/main/device_id_mac.sh | bash -s -- --help 27 | ``` 28 | - 日志 29 | 30 | `~/Library/Application Support/Cursor/User/globalStorage/update.log` 31 | 32 | > 如果你要找storage.json文件位置 33 | > 34 | > %APPDATA%\Cursor\User\globalStorage\storage.json 35 | > 36 | > ~/Library/Application Support/Cursor/User/globalStorage/storage.json 37 | 38 | ## Star History 39 | 40 | [![Star History Chart](https://api.star-history.com/svg?repos=resetsix/cursor_device_id&type=Date)](https://star-history.com/#resetsix/cursor_device_id&Date) 41 | 42 | ## 感谢 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /device_id_mac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Strict mode 4 | set -euo pipefail 5 | 6 | # Config 7 | readonly STORAGE_FILE="$HOME/Library/Application Support/Cursor/User/globalStorage/storage.json" 8 | readonly BACKUP_DIR="$(dirname "$STORAGE_FILE")/backups" 9 | readonly LOG_FILE="$(dirname "$STORAGE_FILE")/update.log" 10 | 11 | # Logger 12 | log() { 13 | echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE" 14 | } 15 | 16 | # Error handler 17 | error() { 18 | log "Error: $1" 19 | exit 1 20 | } 21 | 22 | # Help 23 | usage() { 24 | cat << EOF 25 | Usage: $(basename "$0") [options] 26 | Options: 27 | -h, --help Show help 28 | -m, --machine-id Set machineId (64-bit hex) 29 | -d, --dev-id Set devDeviceId (UUID) 30 | -c, --mac-id Set macMachineId (UUID) 31 | -s, --sqm-id Set sqmId (UUID) 32 | -r, --restore Restore backup 33 | --show Show current IDs 34 | EOF 35 | exit 0 36 | } 37 | 38 | # Generate IDs 39 | generate_machine_id() { 40 | openssl rand -hex 32 || error "Failed to generate machineId" 41 | } 42 | 43 | generate_uuid() { 44 | uuidgen | tr '[:upper:]' '[:lower:]' || error "Failed to generate UUID" 45 | } 46 | 47 | generate_sqm_id() { 48 | echo "{$(uuidgen)}" || error "Failed to generate SQM ID" 49 | } 50 | 51 | # Validate IDs 52 | validate_machine_id() { 53 | [[ $1 =~ ^[0-9a-f]{64}$ ]] || error "Invalid machineId format" 54 | } 55 | 56 | validate_uuid() { 57 | [[ $1 =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]] || error "Invalid UUID format" 58 | } 59 | 60 | validate_sqm_id() { 61 | [[ $1 =~ ^\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}$ ]] || error "Invalid SQM ID format" 62 | } 63 | 64 | # Backup management 65 | backup_file() { 66 | if [[ -f "$STORAGE_FILE" ]]; then 67 | mkdir -p "$BACKUP_DIR" 68 | local backup_file="$BACKUP_DIR/storage_$(date +%Y%m%d_%H%M%S).json" 69 | cp "$STORAGE_FILE" "$backup_file" || error "Backup failed" 70 | chmod 600 "$backup_file" 71 | log "Backup created: $backup_file" 72 | fi 73 | } 74 | 75 | restore_backup() { 76 | local latest_backup=$(ls -t "$BACKUP_DIR"/*.json 2>/dev/null | head -1) 77 | if [[ -n "$latest_backup" ]]; then 78 | cp "$latest_backup" "$STORAGE_FILE" || error "Restore failed" 79 | log "Restored: $latest_backup" 80 | else 81 | error "No backup found" 82 | fi 83 | } 84 | 85 | # Display IDs 86 | show_current_ids() { 87 | if [[ -f "$STORAGE_FILE" ]]; then 88 | echo "Current IDs:" 89 | echo "machineId: $(grep -o '"telemetry\.machineId":\s*"[^"]*"' "$STORAGE_FILE" | cut -d'"' -f4)" 90 | echo "devDeviceId: $(grep -o '"telemetry\.devDeviceId":\s*"[^"]*"' "$STORAGE_FILE" | cut -d'"' -f4)" 91 | echo "macMachineId: $(grep -o '"telemetry\.macMachineId":\s*"[^"]*"' "$STORAGE_FILE" | cut -d'"' -f4)" 92 | echo "sqmId: $(grep -o '"telemetry\.sqmId":\s*"[^"]*"' "$STORAGE_FILE" | cut -d'"' -f4)" 93 | else 94 | error "Storage file not found" 95 | fi 96 | } 97 | 98 | # Update ID 99 | update_id() { 100 | local key=$1 101 | local value=$2 102 | local temp_file="${STORAGE_FILE}.tmp" 103 | 104 | # Create temp file with new content 105 | if [[ -f "$STORAGE_FILE" ]]; then 106 | # Read entire file content 107 | local content 108 | content=$(cat "$STORAGE_FILE") 109 | 110 | # Create new content with updated value 111 | local new_content 112 | new_content=$(echo "$content" | perl -pe 's/"'$key'":\s*"[^"]*"/"'$key'": "'$value'"/g') 113 | 114 | # Write to temp file 115 | echo "$new_content" > "$temp_file" 116 | else 117 | echo '{"'$key'": "'$value'"}' > "$temp_file" 118 | fi 119 | 120 | # Move temp file to original 121 | mv "$temp_file" "$STORAGE_FILE" 122 | 123 | # Set permissions 124 | chmod 600 "$STORAGE_FILE" 125 | 126 | # Force write to disk 127 | sync 128 | 129 | # Verify the change 130 | if ! grep -q "\"$key\": \"$value\"" "$STORAGE_FILE"; then 131 | error "Failed to update $key" 132 | fi 133 | 134 | log "Updated $key: $value" 135 | } 136 | 137 | # Main 138 | main() { 139 | local MACHINE_ID="" 140 | local DEV_ID="" 141 | local MAC_ID="" 142 | local SQM_ID="" 143 | 144 | # Parse args 145 | while [[ $# -gt 0 ]]; do 146 | case $1 in 147 | -h|--help) usage ;; 148 | -m|--machine-id) MACHINE_ID="$2"; shift 2 ;; 149 | -d|--dev-id) DEV_ID="$2"; shift 2 ;; 150 | -c|--mac-id) MAC_ID="$2"; shift 2 ;; 151 | -s|--sqm-id) SQM_ID="$2"; shift 2 ;; 152 | -r|--restore) restore_backup; exit 0 ;; 153 | --show) show_current_ids; exit 0 ;; 154 | *) error "Unknown option: $1" ;; 155 | esac 156 | done 157 | 158 | # Create backup 159 | backup_file 160 | 161 | # Update IDs 162 | if [[ -z "$MACHINE_ID" ]]; then 163 | MACHINE_ID=$(generate_machine_id) 164 | fi 165 | validate_machine_id "$MACHINE_ID" 166 | update_id "telemetry.machineId" "$MACHINE_ID" 167 | 168 | if [[ -z "$DEV_ID" ]]; then 169 | DEV_ID=$(generate_uuid) 170 | fi 171 | validate_uuid "$DEV_ID" 172 | update_id "telemetry.devDeviceId" "$DEV_ID" 173 | 174 | if [[ -z "$MAC_ID" ]]; then 175 | MAC_ID=$(generate_uuid) 176 | fi 177 | validate_uuid "$MAC_ID" 178 | update_id "telemetry.macMachineId" "$MAC_ID" 179 | 180 | if [[ -z "$SQM_ID" ]]; then 181 | SQM_ID=$(generate_sqm_id) 182 | fi 183 | validate_sqm_id "$SQM_ID" 184 | update_id "telemetry.sqmId" "$SQM_ID" 185 | 186 | # Force write to disk 187 | sync 188 | 189 | log "All IDs updated" 190 | show_current_ids 191 | } 192 | 193 | main "$@" -------------------------------------------------------------------------------- /device_id_win.ps1: -------------------------------------------------------------------------------- 1 | # Generate new IDs 2 | $new_machine_id = -join ((1..64) | ForEach-Object { "0123456789abcdef"[(Get-Random -Max 16)] }) 3 | $new_dev_device_id = [guid]::NewGuid().ToString().ToLower() 4 | $new_mac_machine_id = [guid]::NewGuid().ToString().ToLower() 5 | $new_sqm_id = "{" + [guid]::NewGuid().ToString().ToUpper() + "}" 6 | 7 | # File paths 8 | $storage_json_path = "$env:APPDATA\Cursor\User\globalStorage\storage.json" 9 | $backup_dir = "$env:APPDATA\Cursor\User\globalStorage\backups" 10 | 11 | # Create backup directory if not exists 12 | if (-not (Test-Path $backup_dir)) { 13 | New-Item -ItemType Directory -Path $backup_dir | Out-Null 14 | } 15 | 16 | # Create backup with timestamp 17 | $timestamp = Get-Date -Format "yyyyMMdd_HHmmss" 18 | $backup_path = Join-Path $backup_dir "storage_$timestamp.json" 19 | 20 | # Backup existing file 21 | if (Test-Path $storage_json_path) { 22 | Copy-Item $storage_json_path $backup_path 23 | Write-Host "Backup created: $backup_path" 24 | } 25 | 26 | # Update storage.json 27 | if (Test-Path $storage_json_path) { 28 | $content = Get-Content $storage_json_path -Raw | ConvertFrom-Json 29 | } else { 30 | $content = @{} 31 | } 32 | 33 | # Update all IDs 34 | $content.'telemetry.machineId' = $new_machine_id 35 | $content.'telemetry.devDeviceId' = $new_dev_device_id 36 | $content.'telemetry.macMachineId' = $new_mac_machine_id 37 | $content.'telemetry.sqmId' = $new_sqm_id 38 | 39 | # Save changes 40 | $content | ConvertTo-Json -Depth 100 | Out-File $storage_json_path -Encoding UTF8 41 | 42 | # Display results 43 | Write-Host "Successfully updated device IDs:" 44 | Write-Host "machineId: $new_machine_id" 45 | Write-Host "devDeviceId: $new_dev_device_id" 46 | Write-Host "macMachineId: $new_mac_machine_id" 47 | Write-Host "sqmId: $new_sqm_id" --------------------------------------------------------------------------------