caleb531/play-song

None of the commands work

Closed this issue · 40 comments

As of the v2 release none of the commands seems to work, they all return an empty list, so that you can't choose a song/album/etc. to play.

Here's the error message from Alfred's debug console:

Starting debug for 'Play Song'

[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)

Okay, I added a modified workflow on a new branch hotfix/2, which will log the error Alfred 'Workflow Data' folder does not exist if such is true. Please try it and report what happens.
Caleb

I get that error with that version:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)

However, inserting the line tell application "Finder" to return (alias alfredWorkflowDataFolder exists) after the property-statements in Configuration.scpt and running from the Script Editor, I get true as the result.

So it seems like the problem is running it from Alfred.

Ah, okay. Well, in that case, can you change the log message in Configuration.scpt from this:

log "Alfred 'Workflow Data' folder does not exist"

To this:

log ("Alfred 'Workflow Data' folder does not exist: " & (alfredWorkflowDataFolder as text))

Please post the output from the debugger. I have a feeling that AppleScript within Alfred might be improperly constructing the path.

I still get the same output:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: Alfred 'Workflow Data' folder does not exist
execution error: Finder got an error: AppleEvent handler failed. (-10000)

which probably means that Alfred uses a cached version of Configuration.scpt and doesn't update it when installing the workflow.

And it gets even weirder:

Replacing /Users/Tyilo/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.*/Configuration.scpt with the one from hotfix/2 I still get the error.

However changing /Users/Tyilo/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.*/Configuration.scpt directly and changing that line to log ("Alfred 'Workflow Data' folder does not exist: " & (alfredWorkflowDataFolder as text)) have fixed the issue completely! No error is logged and playing works!

That's so bizarre. I wonder if compiling the AppleScript (as you might do in the editor) has something to do with this.

I am still determined to figure this out. Could you try the following:

  1. Replace Configuration.scpt with the one from hotfix/2. See if this breaks the workflow again
  2. Open Configuration.scpt (in the workflow itself) in the Script Editor and press the Compile button. See if the workflow works now
  1. It breaks it
  2. This fixes it again. (Compile + save)

Well, after some quick searching, I've discovered that this might not be an issue with Play Song, but with Alfred. Check out this thread on the Alfred Forums:
http://www.alfredforum.com/topic/1861-applescript-runs-differently-in-alfred-and-in-applescript-editor/

What do you think?

What happens if you change Configuration.scpt to a plaintext script (Configuration.applescript)?

Making all the scripts plaintext is probably also a good idea for viewing the files on GitHub and viewing diffs in git.

AppleScript can only load in scpt files into memory. I could convert them, but then I can't run them in the Script Editor. That might be an acceptable sacrifice, though—version control is more important.

However, I've pushed a new possible fix for hotfix/2 branch. Please download and replace the workflow (yes, the entire workflow) with the new copy. Test the play keyword only. I added a single line after loading in the config script which runs it afterward (run script config), which might trigger a compile and cause it to work.

It still doesn't work, however you can use this bash script to automatically recompile the script:

bundleid="com.calebevans.playsong"

container=""
for f in ~/Library/Application\ Support/Alfred\ 2/Alfred.alfredpreferences/workflows/user.workflow.*/; do
    if plutil -extract bundleid xml1 "$f/info.plist" -o - | grep "$bundleid" &> /dev/null; then
        container="$f"
        break
    fi
done

if [[ "$container" = "" ]]; then
    echo 'Failed to find workflow container directory!'
    exit 1
fi

for f in "$container"/*.scpt; do
    plaintext=$(osadecompile "$f")
    # | sponge |
    echo "$plaintext" | osacompile -o "$f"
done

echo 'Recompiled scripts!'

Oh, that's handy. I'm not sure where/how you came up with that, but cool.

Assuming a modify that bash script accordingly, do you think I could run it on the exported workflow before committing in order to make the workflow work for everyone else? I would not prefer that users of the workflow need to run this in order for the workflow to function, though I wouldn't mind doing so as a final step before committing a new version of the workflow.

I doubt it, as it just does the same as clicking compile and save in Script Editor.

Okay, I've pushed a new update to hotfix/2, this time with the configuration nested inside a script object within the file (which I'm hoping might compile). Please test it and let me know if it works or not (again, test only the play keyword). :)

Thanks,
Caleb

Nope still get the error:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)
[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)

Running my script however still fixes it.

Ah, well, I'm still not giving up.

I've pushed another update to hotfix/2. Please replace the workflow, test the play keyword, and let me know if the results show up this time.

Still doesn't work :/

I have recompiled the latest hotfix/2 Configuration.scpt and uploaded it here: https://a.pomf.se/mkoccc.scpt

If you use that without recompiling it yourself, does it work for you?

I don't think it would matter, anyway. The workflow has been working for me from the very beginning.

However, because we've narrowed the problem down to a compilation issue, and because I've messed around so much with hotfix/2, I decided to delete the branch and re-branch from master. This time, though, I compiled Configuration.scpt using the above Bash script before exporting the workflow and committing.

Please test and see if the workflow on hotfix/2 works for you.

Still doesn't work. I think you might need to include the bash script and run it on installation (or first run) somehow.

Hmm, I think you're right. Therefore, I decided to include compile.sh with the workflow and execute it (via do shell script) when filtering the list of songs.

Again, please test the play keyword and see if it works for you. I realize that it's not at all efficient—it recompiles Configuration.scpt on every keystroke—but I'm just taking this one step at a time.

Caleb

@tyilo, any updates?

Sorry I somehow missed the email sent by GitHub.

It works for me now out of the box! 😄

YES, FINALLY! I can't begin to tell you how happy I am.

Thank you so very much for all of your help in diagnosing this issue. We're almost done. ;)

Now, I shall apply the fix to the other parts of the workflow (in addition to optimizing the Bash script to run once). I hope to push the updated build to GitHub within the next few days, at which point I will need your assistance one last time to ensure that everything works.

Caleb

Cool, thanks ;)

Also @tyilo, do you know of any way to detect (via Bash) if an AppleScript (*.scpt) has been compiled? I'm pondering ways to detect when the script has already been compiled, and so far, I can only think of the "create some file and check if it exists" approach.

Maybe by running the Configuration.scpt with osascript and checking if the workflow data path exists? I'm not sure that it will work, as I think that the problem occurs when Alfred is running it.

An alternative solution: don't include Configuration.scpt, but include Configuration.applescript instead. Then check if Configuration.scpt exists, if not then run osacompile < Configuration.applescript -o Configuration.scpt.

I think that alternative solution is quite brilliant. Implementing it would enable me to more easily migrate from .scpt files to .applescript files. That is, I would never need to manually compile Comfiguration.applescript into Configuration.scpt—the workflow would handle that for me.

I will surely implement this and respond here once I do. :)
Caleb

While you're at it convert the other .scpt to .applescript too if possible.

Oh, believe me—I was already planning on it. Long live UTF-8!

Okay, @tyilo, I implemented the fix! Please download the workflow from hotfix/2 and test all aspects of the workflow so I can merge this in.

Thanks very much,
Caleb

Damn, I get the same error again:

[ERROR: alfred.workflow.input.scriptfilter] Code 1: execution error: Finder got an error: AppleEvent handler failed. (-10000)

The Configuration.scpt exists in the workflows folder after trying to use play, however it doesn't seem to work. However if I manually go to that directory and delete the Configuration.scpt and run bash ./compile.sh it works! This doesn't make any sense to me at all.

Oh, duh. Just realized that I left my already-compiled version of Configuration.scpt in the workflow folder before exporting. If I delete it, a new compiled version should automatically be created when you run the workflow.

Hang on,
Caleb

Okay, @tyilo, pushed a new commit to hotfix/2 branch. Again, please download and test—it should work this time.

Caleb

It works, yay!

Fantastic—absolutely fantastic. Let's merge this in and go home. ;)

Thanks again so very much for all of your help.
Caleb

And... the fix has been merged in! I will gladly close the issue now. :)

Caleb