chew-z / itunes.vim

Fuzzy search and play iTunes tracks in VIM. You have no idea what hides in your Music Library.
GNU General Public License v3.0
9 stars 0 forks source link

osacompile javascript error #1

Closed mattmartini closed 6 years ago

mattmartini commented 6 years ago

This looks like a great plugin, but the scpt would not run so I figured I would compile them as you suggest.

$ osacompile -l JavaScript -o iTunes_Search_fzf.scpt iTunes_Search_fzf.js

But then I get this error message:

iTunes_Search_fzf.js:7: error: Error on line 8: SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode. (0)

If I comment out 'use strict'; then I get this error message:

iTunes_Search_fzf.js:14: error: Error on line 15: SyntaxError: Unexpected identifier 'i'. Expected either 'in' or 'of' in enumeration syntax. (0)

I get the same issue with compiling all of the javascript files

chew-z commented 6 years ago

Hmm. I just checked and it compiles on my machine exactly as it is both with 'const' and without. So I cannot replicate this error.

chew-z commented 6 years ago

Are you on macOS Sierra? JXA changed significantly in Sierra.

You could try changing all 'const' (and 'let') declarations to 'var'...

mattmartini commented 6 years ago

My OS is Yosemite.

I'll give 'let' a try

Sent from my iPad

On Oct 21, 2017, at 1:33 AM, Robert J. notifications@github.com wrote:

Are you on macOS Sierra? JXA changed significantly in Sierra.

You could try changing all 'const' (and 'let') declarations to 'var'...

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chew-z commented 6 years ago

ES6 is part of JXA since Sierra (it is compatible with JS in Safari ~10.1).

I'am afraid that arrow functions might not compile as well. They could be changed into simple statements however. This is how I have written them in the beginning before switching to arrow notation.

Let me know how it goes.

Nice that someone uses Yosemite. ;)

mattmartini commented 6 years ago

Can you send me a copy of one of the old versions with the for loops instead of arrows, I can’t find a version this old in your git history.

I’m stuck on Yosemite because I have a very large collection of photos in Aperture and it isn’t supported on anything later.

On Oct 21, 2017, at 3:05 AM, Robert J. notifications@github.com wrote:

(Most of) ES6 is part of JXA since Sierra (it is compatible with JS in Safari ~10.1).

I'am afraid that arrow functions might not compile as well. They could be changed into simple for loops however. This is how I have written them in the beginning before switching to arrow notation.

Let me know how it goes.

Nice that someone uses Yosemite. ;)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chew-z/itunes.vim/issues/1#issuecomment-338369581, or mute the thread https://github.com/notifications/unsubscribe-auth/AADPOgg6REh6QhcfHLU2ISkbrmqJbdECks5suZfAgaJpZM4P_kEA.

chew-z commented 6 years ago

OK. In folder autoload you will now find two scripts Play.js and Search.js. You can compile them with:

osacompile -l JavaScript -o iTunes_Play_Playlist_Track.scpt Play.js

osacompile -l JavaScript -o iTunes_Search2_fzf.scpt Search.js

I have removed 'const' and 'let' and rewritten arrow functions as regular functions. It should be kosher pre-ES6 javascript now. It compiles on my machine but of course I cannot check it on Yosemite so please let me know if you get errors. I hope not.

Update the plugin please - I have removed one line from itunes.vim as iTunes_Search_fzf.scpt isn't necessary.

mattmartini commented 6 years ago

On Oct 22, 2017, at 5:42 AM, Robert J. notifications@github.com wrote:

OK. In folder autoload you will now find two scripts Play.js and Search.js. You can compile them with:

osacompile -l JavaScript -o iTunes_Play_Playlist_Track.scpt Play.js

osacompile -l JavaScript -o iTunes_Search2_fzf.scpt Search.js I have removed 'const' and 'let' and rewritten arrow functions as regular functions. It should be kosher pre-ES6 javascript now. It compiles on my machine but of course I cannot check it on Yosemite so please let me know if you get errors. I hope not.

Update the plugin please - I have removed one line from itunes.vim as iTunes_Search_fzf.scpt isn't necessary.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chew-z/itunes.vim/issues/1#issuecomment-338464618, or mute the thread https://github.com/notifications/unsubscribe-auth/AADPOsXjc0gpcDRFRWp9KJ4Zbg-taVGnks5suw4DgaJpZM4P_kEA.

$ osacompile -l JavaScript -o iTunes_Play_Playlist_Track.scpt Play.js Play.js:29: error: Error on line 29: SyntaxError: Unexpected token '>' (0)

Commenting out this line (looks like just logging) let it compile ok.

// if (verbose) { tracks.forEach(t => { console.log(t.id(), t.name()) } ) }

$ osacompile -l JavaScript -o iTunes_Search2_fzf.scpt Search.js Search.js:39: error: Error on line 40: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. (0)

chew-z commented 6 years ago

I assume it is the line

function flatten(arr) { return Array.prototype.concat.apply([], arr); }

Have changed to more conservative as in this discussion.

        function flatten(arr) { 
            var flat = [].concat.apply([], arr);
            return flat; 
        }

Tell me if it compiles now on your machine.

mattmartini commented 6 years ago

Play.js compiles fine.

Search gives this error:

$ osacompile -l JavaScript -o iTunes_Search2_fzf.scpt Search.js Search.js:39: error: Error on line 40: SyntaxError: Strict mode does not allow function declarations in a lexically nested statement. (0)

Thanks for spending the time on this!!

On Oct 23, 2017, at 12:01 AM, Robert J. notifications@github.com wrote:

I assume it is the line

function flatten(arr) { return Array.prototype.concat.apply([], arr); }

Have changed to more conservative as in this discussion https://groups.google.com/forum/#!topic/eslint/rXUGQajHpzo.

    function flatten(arr) { 
        var flat = [].concat.apply([], arr);
        return flat; 
    }

Tell me if it compiles now on your machine.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chew-z/itunes.vim/issues/1#issuecomment-338542178, or mute the thread https://github.com/notifications/unsubscribe-auth/AADPOiTjejATrqclHiZabX-BSBYu8Swcks5svA-OgaJpZM4P_kEA.

chew-z commented 6 years ago

Hmm.

Line 39 is this: if (verbose) { playlists.forEach( function(p) { console.log(p.name(), p.class()) }) } and line 40 is empty.

Try commenting it out. It isn't necessary, just logging. You could also try commenting out 'use strict' as an alternative.

Thanks for spending the time on this!!

My pleasure. It is quite funny challenge :) Would be easier if I had Yosemite on my machine though.

mattmartini commented 6 years ago

Ok, got everything to compile.

Line 39 was not a problem, but I had to comment out use strict. I had to change the backticks to quotes in lines 52 and 61.

Got vim to load it, but doing :Tunes gives me:

Let me get iTunes Library first Error detected while processing function RefreshLibrary_JobEnd[1]..103_restoreVariable: line 2: E684: list index out of range: 0 E15: Invalid expression: readfile(a:file)[0] line 6: E121: Undefined variable: l:recover E15: Invalid expression: 'let l:result = ' . l:recover line 7: E121: Undefined variable: l:result E15: Invalid expression: l:result iTunes Library refreshed

and

$ cat iTunes_Library_Cache.txt 0

I think we are chasing a ghost here.

On Oct 23, 2017, at 8:13 PM, Robert J. notifications@github.com wrote:

Hmm.

Line 39 is this: if (verbose) { playlists.forEach( function(p) { console.log(p.name(), p.class()) }) } and line 40 is empty.

Try commenting it out. It isn't necessary, just logging. You could also try commenting out 'use strict' as an alternative.

Thanks for spending the time on this!!

My pleasure. It is quite funny challenge :) Would be easier if I had Yosemite on my machine though.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chew-z/itunes.vim/issues/1#issuecomment-338832822, or mute the thread https://github.com/notifications/unsubscribe-auth/AADPOjjDG3vfQroCynk10k1zv5G08BYLks5svSu2gaJpZM4P_kEA.

chew-z commented 6 years ago

You might go to autoload folder in terminal and do osascript -l JavaScript iTunes_Search2_fzf.scpt. It might take a moment but you should the results - all your iTunes Library in JSON like form. That would confirm that Search.js script works.

also add let g:itunes_verbose =1 in .vimrc before start.

I think we are chasing a ghost here.

Yes, maybe. Pity I was hoping it is more robust plugin.

mattmartini commented 6 years ago

On Oct 25, 2017, at 2:17 PM, Robert J. notifications@github.com wrote:

You might go to autoload folder in terminal and do osascript -l JavaScript iTunes_Search2_fzf.scpt. It might take a moment but you should the results - all your iTunes Library in JSON like form. That would confirm that Search.js script works.

also add let g:itunes_verbose =1 in .vimrc before start.

I think we are chasing a ghost here.

Yes, maybe. Pity I was hoping it is more robust plugin.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/chew-z/itunes.vim/issues/1#issuecomment-339422646, or mute the thread https://github.com/notifications/unsubscribe-auth/AADPOj0Oxfdhi5AWSUjHzegooMhL6R7aks5sv3tVgaJpZM4P_kEA.

$ osascript -l JavaScript iTunes_Search2_fzf.scpt

Library Error: Can't convert types.

With verbose on:

In Vim:

:Tunes /Volumes/Vault/Users/merm/Projects/VIM/itunes.vim/autoload /Volumes/Vault/Users/merm/Projects/VIM/itunes.vim/autoload/iTunes_Play_Playlist_Track.scpt /Volumes/Vault/Users/merm/Projects/VIM/itunes.vim/autoload/iTunes_Search2_fzf.scpt /Volumes/Vault/Users/merm/Projects/VIM/itunes.vim/autoload/iTunes_Library_Cache.txt Let me get iTunes Library first ['osascript', '-l', 'JavaScript', '/Volumes/Vault/Users/merm/Projects/VIM/itunes.vim/autoload/iTunes_Search2_fzf.scpt', 'Offline'] '/var/folders/jv/p1y0rbld1m55kntr6jl6602h0000w5/T/v7rvanC/2' Refreshing iTunes Library in background Press ENTER or type command to continue Error detected while processing function RefreshLibrary_JobEnd[1]..103_restoreVariable: line 2: E684: list index out of range: 0 E15: Invalid expression: readfile(a:file)[0] line 6: E121: Undefined variable: l:recover E15: Invalid expression: 'let l:result = ' . l:recover line 7: E121: Undefined variable: l:result E15: Invalid expression: l:result iTunes Library refreshed RefreshLibrary job finished with 1 items

chew-z commented 6 years ago

Error: Can't convert types.

If you can't see any results it looks like Play.js despite compiling OK is failing due to some type conversion. And later vim script (async job that should handle results) fails due to empty iTunes_Library_Cache.txt.

This is a mystery to me.

All I can advice to you is to tinker with Play.js still more. It is probably something small. Something stupid that works on Sierra and not Yosemite. Difficult for me to help without having Yosemite.

Apple did poor job implementing JXA so it might be but let's not blame Apple for all evils of the world.

mattmartini commented 6 years ago

Could you send me a small sample cache file so I can create one of my own and see if the player works. It seems that the cache file is failing to be generated ( I just get a file with a zero in it).

Also, along the way at one point I changed two sets of backticks to quotes. Were those supposed to be quotes, or backticks that would've spanned a subshell?

Sent from my iPad

On Oct 27, 2017, at 3:54 AM, Robert J. notifications@github.com wrote:

Error: Can't convert types.

If you can't see any results it looks like Play.js despite compiling OK is failing due to some type conversion. And later vim script (async job that should handle results) fails due to empty iTunes_Library_Cache.txt.

This is a mystery to me.

All I can advice to you is to tinker with Play.js still more. It is probably something small. Something stupid that works on Sierra and not Yosemite. Difficult for me to help without having Yosemite.

Apple did poor job implementing JXA so it might be but let's not blame Apple for all evils of the world.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

chew-z commented 6 years ago

Search.js should return array of JSON objects with song id, name, album, collection (playlist in iTunes speak) and artist (see below). This is exactly what goes into iTunes_Library_Cache.txt.

I have uploaded script Search2.js - could you please use it instead of Search.js? The difference is in this line:

return { id: t.id(), name: t.name(), album: t.album(), collection: p.name(), artist: t.artist() }

and it is important as it saves array of JSON instead of |-separated items. Perhaps it will compile now right away.

[{"id":79336,"name":"Ol'55 (Freedom Sessions)","album":"Fumbling Towards Ecstasy (Legacy Edition) [Audio Version]","collection":"Waits by Women","artist":"Sarah McLachlan"},{"id":79340,"name":"Rise n Shine (feat. Poo Bear)","album":"Rise n Shine (feat. Poo Bear) - Single","collection":"Women who Dj","artist":"Eva Shaw"},{"id":79342,"name":"Hey Lion","album":"Soft Animals - EP","collection":"Women who Dj","artist":"Sofi Tukker"},{"id":79343,"name":"Do You (Juliet Fox Remix)","album":"Combinations - Single","collection":"Women who Dj","artist":"Gallya"},{"id":79344,"name":"Animal (feat. Scott Bernhardt) [not sorry Remix]","album":"Animal (feat. Scott Bernhardt) [Remixes] - EP","collection":"Women who Dj","artist":"Reid Speed"}......