applescript_client
¶
AppleScript Client Module.
This module provides an abstraction for executing AppleScript commands asynchronously.
It centralizes the logic for interacting with AppleScript via the osascript command,
handles errors, applies concurrency limits via semaphore-based control, and ensures non-blocking execution.
AppleScriptClient
¶
Bases: AppleScriptClientProtocol
A client to run AppleScript commands asynchronously using the osascript command.
Semaphore initialization is done in the async initialize method.
Initialize the AppleScript client.
Source code in src/services/apple/applescript_client.py
initialize
async
¶
Asynchronously initializes the AppleScriptClient by creating the semaphore.
Must be called within an active event loop.
Source code in src/services/apple/applescript_client.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | |
run_script
async
¶
run_script(
script_name,
arguments=None,
timeout=None,
context_artist=None,
context_album=None,
context_track=None,
label=None,
)
Execute an AppleScript file and return its output.
Requires initialize() to be called first to set up the AppleScript directory path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
script_name
|
str
|
Name of the AppleScript file to execute. |
required |
arguments
|
list[str] | None
|
Optional list of arguments to pass to the script. |
None
|
timeout
|
float | None
|
Optional timeout in seconds. Uses default from config if not specified. |
None
|
context_artist
|
str | None
|
Artist name for contextual logging. |
None
|
context_album
|
str | None
|
Album name for contextual logging. |
None
|
context_track
|
str | None
|
Track name for contextual logging. |
None
|
label
|
str | None
|
Custom label for logging (defaults to script_name). |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The stdout output from the AppleScript execution, or None if an error occurred. |
Raises:
| Type | Description |
|---|---|
TimeoutError
|
If script execution times out. |
OSError
|
If script execution fails. |
Source code in src/services/apple/applescript_client.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
fetch_tracks_by_ids
async
¶
Fetch tracks by their IDs using fetch_tracks_by_ids.applescript.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track_ids
|
list[str]
|
List of track IDs to fetch |
required |
batch_size
|
int
|
Maximum number of IDs per batch (default: 1000) |
1000
|
timeout
|
float | None
|
Timeout in seconds for script execution |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
List of track dictionaries with metadata |
Source code in src/services/apple/applescript_client.py
fetch_all_track_ids
async
¶
Fetch just track IDs from Music.app (lightweight operation).
This is used by Smart Delta to detect new/removed tracks without fetching full metadata. Much faster than fetching all track data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float | None
|
Timeout in seconds for script execution |
None
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of track ID strings |