{"id":19425735,"url":"https://github.com/sonsongithub/applescriptbridge","last_synced_at":"2025-04-24T16:31:42.864Z","repository":{"id":260449679,"uuid":"868037401","full_name":"sonsongithub/AppleScriptBridge","owner":"sonsongithub","description":"Swift code to manage \"Music.app\" using AppleScript.","archived":true,"fork":false,"pushed_at":"2024-11-05T12:29:00.000Z","size":30,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-25T05:14:50.003Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sonsongithub.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-05T10:05:34.000Z","updated_at":"2025-02-23T12:18:29.000Z","dependencies_parsed_at":"2024-10-31T12:31:23.432Z","dependency_job_id":null,"html_url":"https://github.com/sonsongithub/AppleScriptBridge","commit_stats":null,"previous_names":["sonsongithub/applescriptbridge"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonsongithub%2FAppleScriptBridge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonsongithub%2FAppleScriptBridge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonsongithub%2FAppleScriptBridge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonsongithub%2FAppleScriptBridge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonsongithub","download_url":"https://codeload.github.com/sonsongithub/AppleScriptBridge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250663544,"owners_count":21467366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T14:04:40.599Z","updated_at":"2025-04-24T16:31:42.556Z","avatar_url":"https://github.com/sonsongithub.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n**This project is archived. Please refer to [the new project](https://github.com/sonsongithub/MusicConMenu).**\n\n# AppleScriptBridge\nSwift code to manage \"Music.app\" using AppleScript.\n\n# Capability and privacy setting\n\nAt first, you have to add the following privacy authentication phrase to the `Info.plist`.\n\n\u003cimg src=\"https://github.com/user-attachments/assets/0fc516b3-2b51-46b2-ae11-c7d0f63e85c7\"\u003e\n\n## Permit the application to use AppleEvent.\n\n\u003cimg src=\"https://github.com/user-attachments/assets/915f8ab9-8b79-4747-a5b2-bd459c596aa0\"\u003e\n\n## Permit to communicate with Music.app.\n\n\u003cimg src=\"https://github.com/user-attachments/assets/f067a910-3460-4388-8045-424acdfa2cd4\"\u003e\n\n# ScriptBridge\n\n## Create Music.h using `sdef`\n\n```\nsdef /System/Applications/Music.app | sdp -fh --basename Music\n```\n\n## Import header file\n\nAdded Music.h to the Xcode project.\n\n## Create Bridging Header\n\nAt first, create a dummy objective-c sources and then Xcode will ask you to create a bridging header.\n\n\u003cimg src=\"https://github.com/user-attachments/assets/e02c4c85-4b30-4f4d-bfde-c8293e96d14f\" width=600\u003e\n\n\u003cimg src=\"https://github.com/user-attachments/assets/acea7e87-3727-402d-b49f-aa7a4c417b09\" width=600\u003e\n\n\u003cimg src=\"https://github.com/user-attachments/assets/3e6a889d-1c54-42e1-9f92-d8a170ff040e\" width=600\u003e\n\nYou can add the following line to the bridging header.\n\n```objc\n//\n//  Use this file to import your target's public headers that you would like to expose to Swift.\n//\n\n#import \"Music.h\"\n```\n\n## Prepare interface to write Swift code\n\nYou have to prepare the interface to write Swift code.\nBut, I've already implemented [the python script](https://github.com/sonsongithub/AppleScriptBridge/blob/main/converter.py) to extract the Swift interface from the header file.\n\n```bash\npython converter.py ./AppleScriptBridge/Music.h ./AppleScriptBridge/Music.swift\n```\n\n## Write Swift code\n\n```swift\nif let musicApp: MusicApplication = SBApplication(bundleIdentifier: \"com.apple.Music\") {\n    if let song = musicApp.currentTrack {\n        print(song.name)\n        print(song.artist)\n    }\n}\n```\n\n# NSAppleScript\n\nWe can also use `NSAppleScript` to execute AppleScript.\nThis way requres us to write AppleScript codes and implement some classes or structs to handle the result. Refer to [the example](https://github.com/sonsongithub/AppleScriptBridge/blob/main/AppleScriptBridge/AppleScriptManager.swift).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonsongithub%2Fapplescriptbridge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonsongithub%2Fapplescriptbridge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonsongithub%2Fapplescriptbridge/lists"}