Post

Replies

Boosts

Views

Activity

Moved from macOs 15.8.1 to 27.0.1 and now my osascript runs dog slow
Years ago I used the Last.fm website to keep track of the music I played. It was great because it kept track of music that I played from iTunes and when I connected my iPhone to my computer. The Last.fm software could determine which songs I played on my phone and the software would update the last.fm website. I don't using streaming sites because I don't believe in paying to rent music. I have all my music on my phone and I want to keep track of what I played each month and hence each year. When iTunes went away my iPhone was now mounted under Finder. The Last.fm software could no longer see what songs I played on my phone. So I looked into using osascript to read the Music app and write out each song to a flat file. I would do this after connecting my phone and after playing songs from Music (on the actual computer). I would then do a diff of the two database files to create a counts file. (This is a pretty brute force way of doing things. I get that.) The thing it it took less than 2 minutes to accomplish so I was satisfied with it. A typical flat file resulted over 20,000 lines. Now that I have moved to macOs 27 this is taking too long (less than 2 minutes to hours). So, could some one help and see how I could improve this script, I would appreciate it. Also, I am open with getting the songs I played another way if it is simpler. #!/usr/bin/osascript set p to "./" set a to POSIX file p set filepath to (a as «class utf8») & "out.txt" set openfile to open for access file filepath with write permission tell application "Music" set allTracks to tracks repeat with index from 1 to the count of allTracks set theTrack to item index of allTracks get {artist, album, name, played date, played count, time, media kind} of theTrack set theArtist to artist of theTrack if (theArtist is not "NPR" and theArtist is not "") and (theArtist is not "MusicRadar.com") then set theAlbum to album of theTrack if (theAlbum is not "KEXP Video of the Week") then set mediakind to media kind of theTrack if mediakind as text is "song" then set theArtist to my makePretty(theArtist) set theName to name of theTrack set lastPlayDate to played date of theTrack set thePlayCount to played count of theTrack set theTime to time of theTrack set theLine to theArtist & " -;- " & theAlbum & " -;- " & theName & " -;- " & lastPlayDate & " -;- " & thePlayCount & " -;- " & theTime write theLine & " " to openfile end if end if end if end repeat end tell close access openfile on makePretty(theArtist) set myName to theArtist if myName is "some artist" then set myName to "some new artist" end if return myName end makePretty
0
0
225
8h
Moved from macOs 15.8.1 to 27.0.1 and now my osascript runs dog slow
Years ago I used the Last.fm website to keep track of the music I played. It was great because it kept track of music that I played from iTunes and when I connected my iPhone to my computer. The Last.fm software could determine which songs I played on my phone and the software would update the last.fm website. I don't using streaming sites because I don't believe in paying to rent music. I have all my music on my phone and I want to keep track of what I played each month and hence each year. When iTunes went away my iPhone was now mounted under Finder. The Last.fm software could no longer see what songs I played on my phone. So I looked into using osascript to read the Music app and write out each song to a flat file. I would do this after connecting my phone and after playing songs from Music (on the actual computer). I would then do a diff of the two database files to create a counts file. (This is a pretty brute force way of doing things. I get that.) The thing it it took less than 2 minutes to accomplish so I was satisfied with it. A typical flat file resulted over 20,000 lines. Now that I have moved to macOs 27 this is taking too long (less than 2 minutes to hours). So, could some one help and see how I could improve this script, I would appreciate it. Also, I am open with getting the songs I played another way if it is simpler. #!/usr/bin/osascript set p to "./" set a to POSIX file p set filepath to (a as «class utf8») & "out.txt" set openfile to open for access file filepath with write permission tell application "Music" set allTracks to tracks repeat with index from 1 to the count of allTracks set theTrack to item index of allTracks get {artist, album, name, played date, played count, time, media kind} of theTrack set theArtist to artist of theTrack if (theArtist is not "NPR" and theArtist is not "") and (theArtist is not "MusicRadar.com") then set theAlbum to album of theTrack if (theAlbum is not "KEXP Video of the Week") then set mediakind to media kind of theTrack if mediakind as text is "song" then set theArtist to my makePretty(theArtist) set theName to name of theTrack set lastPlayDate to played date of theTrack set thePlayCount to played count of theTrack set theTime to time of theTrack set theLine to theArtist & " -;- " & theAlbum & " -;- " & theName & " -;- " & lastPlayDate & " -;- " & thePlayCount & " -;- " & theTime write theLine & " " to openfile end if end if end if end repeat end tell close access openfile on makePretty(theArtist) set myName to theArtist if myName is "some artist" then set myName to "some new artist" end if return myName end makePretty
Replies
0
Boosts
0
Views
225
Activity
8h