script-commands icon indicating copy to clipboard operation
script-commands copied to clipboard

Applescript with emoji icon fail to run

Open Pustelto opened this issue 6 years ago • 22 comments

Hi,

first of all I want to say that I love what you are doing with Raycast. I'm tweaking it a bit with script and I have bumbed to tricky issue. When I try to run applescript in Raycast to which contains emoji icon it won't run if there is a tell block over multiple lines.

I have tried sleep command from this repo and it worked fine. But when I tried to run toggle-desktop-icons it failed and nothing happen. I have tried to change mode to compact and it write Operaction couldn't be completed. Exec format error.. But if I delete # @raycast.icon line script works.

macOS version 10.15.7

Tested it with Raycast 1.1.0 and 1.1.1.

Pustelto avatar Nov 12 '20 04:11 Pustelto

Hi @Pustelto. Thanks for reporting. That's indeed a tricky issue. I haven't managed to reproduce this problem locally (macos 10.15.7). Did you see this error when running any other apple scripts with emoji icon?

Also could you try switching mode to fullOutput and tell me what do you see there?

PitNikola avatar Nov 15 '20 20:11 PitNikola

Hi, I had this issue on 10.15.x version (not sure about exact version though, and it's still there in macOS 11.0.1). I tested it with my custom apple script to connect to VPN. The issues was the same. Adding fullOutput doesn't give much help since there is not error at all (see the attached pic). However if I run the script in Apple's ScriptEditor it works. So problem is probably not with the script itself.

I am running zsh shell v5.8 (x86_64-apple-darwin20.0), if that have any value in this case. Also including screens of my scripts setup. Snímek obrazovky 2020-11-16 v 14 00 20 Snímek obrazovky 2020-11-16 v 14 01 23 Snímek obrazovky 2020-11-16 v 13 53 42

Pustelto avatar Nov 16 '20 13:11 Pustelto

@PitNikola I try to remove # @racast.icon but always send me an error :( Here's my script, may help you to reproduce the issue:

#!/usr/bin/osascript
# @raycast.title Open with Chrome
# @raycast.author Siyuan Zhang
# @raycast.authorURL https://github.com/kastnerorz
# @raycast.description Open Current Safari Tab with Chrome
# @raycast.icon 🧭
# @raycast.mode silent
# @raycast.packageName system
# @raycast.schemaVersion 1
tell application "Safari"
	set currentUrl to URL of current tab of front window
end tell
tell application "Google Chrome"
	open location currentUrl
end tell

zsypsilon avatar Dec 07 '20 12:12 zsypsilon

@kastnerorz your script works on my machine. What error do you get when removing the @raycast.icon from the script? Also, could you make sure to set the encoding to UTF-8. I attached a screenshot on how to do it in VS Code. We encountered some issues in the community that the encoding was sometimes set to something else for AppleScript and it broke the execution.

CleanShot 2020-12-12 at 11 57 34@2x

thomaspaulmann avatar Dec 12 '20 11:12 thomaspaulmann

@thomaspaulmann I tried to re-save toggle-desktop-icons.applescript taken from your repo to UTF-8 (was UTF-16 LE), but after that if I refresh the scripts in raycast settings I don't see the script anymore at all.

Pustelto avatar Dec 12 '20 12:12 Pustelto

That is even weirder. Did you make sure that the script is executable? You can run chmod +x <path to file> to make it executable. When you just download the file, the flag is sometimes not set.

thomaspaulmann avatar Dec 12 '20 12:12 thomaspaulmann

@thomaspaulmann I think it's the encoding issue. I saved it with script editor, after I copy and re-edit with vim, it works.

zsypsilon avatar Dec 12 '20 17:12 zsypsilon

Great! I'm gonna close this issue then. Might be worth to add something to the AppleScript template or setup.

thomaspaulmann avatar Dec 12 '20 17:12 thomaspaulmann

@thomaspaulmann I tried to change encoding to UTF-8, but still no success. I still have problems to add icons to some other apple scripts (icon is not displayed). I will try to rewrite non-working apple script from scratch in UTF-8 to double check, but so far this seems like not-working for me. I have checked the permission and I have execute permission for all my scripts.

Pustelto avatar Dec 14 '20 09:12 Pustelto

In case it is still helpful to anyone:

I just tried creating an applescript script and I got hit with [Exec format error] when trying to run it. After reading this thread, removing the default Raycast line # @raycast.icon 🤖 solved the problem.

santiago-coastpay-com avatar Jun 27 '22 20:06 santiago-coastpay-com

This issue does not seem to be resolved, it seems to happen with every AppleScript created through Raycast.

Is it possible that when Raycast generates a new AppleScript file, it saves it with the wrong character encoding? At the least, the issue seems to be caused by the Emoji that Raycast is adding to the generated file, and it would be resolved by removing that.

RobinDaugherty avatar Aug 17 '22 13:08 RobinDaugherty

could you make sure to set the encoding to UTF-8. I attached a screenshot on how to do it in VS Code. We encountered some issues in the community that the encoding was sometimes set to something else for AppleScript and it broke the execution.

I was having this issue, and the above suggestion fixed it for me. In VSC I've re-saved the file with UTF-8 encoding and my script started working, without making any other change.

linuz90 avatar Oct 14 '22 12:10 linuz90

Also, could you make sure to set the encoding to UTF-8. I attached a screenshot on how to do it in VS Code.

FYI: I was having the same issue. Above suggestion from @thomaspaulmann fixed it. For some reason every time I edit the script in Script Editor it encodes it as UTF-16, and then Raycast won't run the script. Changing the script file to UTF-8 fixes that.

mSarheed avatar Jan 20 '23 11:01 mSarheed

Yeah Script Editor is a bit annoying. I would suggest to edit it in another editor like VS Code.

thomaspaulmann avatar Jan 20 '23 14:01 thomaspaulmann

I am not quite sure, whether it is related to this issue, but I have a script that works as expected with Script Editor. As soon as I want to run it with Raycast, the script is not working. I am getting an error that the "tell" command is not found. It is already saved as UTF-8.

jbueter avatar Feb 16 '23 10:02 jbueter

Would be useful to get an error message stating that the file was saved in the wrong encoding. Just spent half an hour troubleshooting due to the Script Editor saving it in UTF16 by default. After setting the encoding to UTF8 it worked again, but the error message I got wasn't helpful:

Reason: Process tried to run, but failed Domain: scripts Time: 12:25:51.852 Underlying: Domain: NSPOSIXErrorDomain 8 Reason: Exec format error

I hope by putting this here, people will find the resolution easier. Bonus points if Raycast could hint to the user that the encoding isn't correct.

thomasbaart avatar Apr 24 '23 12:04 thomasbaart

Adding to the comment above Note that VSCode will give you the encoding in its status bar.

Also @thomasbaart thanks for the Kyria!

ramnathk avatar Oct 16 '23 16:10 ramnathk

You can force-change the encoding in VS Code using the command palette:

  1. Screenshot 2024-03-04 at 13 59 58
  2. Screenshot 2024-03-04 at 14 00 40
  3. Screenshot 2024-03-04 at 14 00 04

SimeonGriggs avatar Mar 04 '24 14:03 SimeonGriggs

Same issue in 2024. Switching the encoding to UTF-8 in Sublime seems to fix it. Raycast should implement a fix.

dudido avatar Aug 17 '24 20:08 dudido

Same issue in 2024. Switching the encoding to UTF-8 in Sublime seems to fix it. Raycast should implement a fix.

here is already a clear solution, and I don’t think it’s too troublesome to implement. As for why the Raycast maintainers haven’t done this, I don’t understand. I support you.

bycszzz avatar Sep 24 '24 01:09 bycszzz