import ScriptingBridge
+import Foundation
// Protocol to obtain the track from iTunes
@objc protocol iTunesTrack {
// Calls the spotify API and returns the current track
var currentTrack: Track? {
- if let iTunes: iTunesApplication = SBApplication(bundleIdentifier: "com.apple.iTunes") {
+ if let iTunes: iTunesApplication = SBApplication(bundleIdentifier: bundleIdentifier) {
+ if let application = iTunes as? SBApplication {
+ if !application.isRunning {
+ return nil
+ }
+ }
// Attempt to fetch the title from a stream
if let currentStreamTitle = iTunes.currentStreamTitle {
return nil
}
+ private var bundleIdentifier: String {
+ if ProcessInfo().isOperatingSystemAtLeast(
+ OperatingSystemVersion(majorVersion: 10, minorVersion: 15, patchVersion: 0)
+ ) {
+ return "com.apple.Music"
+ }
+
+ return "com.apple.iTunes"
+ }
+
}
var currentTrack: Track? {
if let spotify: SpotifyApplication = SBApplication(bundleIdentifier: "com.spotify.client") {
+ if let application = spotify as? SBApplication {
+ if !application.isRunning {
+ return nil
+ }
+ }
// Attempt to fetch the title from a song
+
if let currentTrack = spotify.currentTrack {
if let track = currentTrack {
if let name = track.name {