Help With AppleScript, Please

Hi,

I've been using the script below in conjunction with a Streamdeck for some time. Suddenly it no longer works. As far as I know, I have made no changes.

Could someone look at it and tell me if it should work? I'm sure I downloaded it from here originally and made minor changes. Thanks.

tell application "Mail"
	set selMessage to selection
	set thisMessage to item 1 of selMessage
	set mailbox of thisMessage to mailbox "Waiting" of account "**account name**"
	display notification with title "Message Moved to Waiting Folder"
end tell

Just to confirm, your personal copy of the script does contain an actual account name, correct? I'm assuming you put in **account name** for privacy purposes here?

I just ran this on my end and after supplying an account name it works for me.

Do you reference the AppleScript via a file path in the Stream Deck app? Just yesterday I realized the reason several of my buttons stopped working was because I had moved some files around and the Stream Deck could no longer find the AppleScript files from the file path I had previously supplied.

Hi, yes that is just a placeholder, my copy has the account name.

I use the KM link option in Stream Deck which gives a drop-down menu of all my KM macros to choose from.
Cheers

That’s probably the issue. I like KM Link but from time to time they stop working and I have to replace the button. No clue why, but I’ve come across others online who have the same issue occasionally. Try these in the following order to rule out an issue with Stream Decks plugin.

  1. Reselecting the macro in the KM Link dropdown menu.
  2. Copying the button and pasting to another location, then running it from there.
  3. Deleting the button and recreating it.

Yes, tried all that but still no help, that's why I wondered if the script had errors.
Cheers

Can you run the script directly from an AppleScript editor like Script Editor, or better yet, Script Debugger and see what the output is?

Hmm
I got this

error "Mail got an error: Can’t set mailbox "Waiting" of account "accountname" to mailbox "Waiting" of account "accountname"." number -10006 from mailbox "Waiting" of account "accountname"

(account name redacted)

That means it's not finding that mailbox. Did you accidentally delete it by chance?

So KMLink probably doesn’t seem to be the issue… :smirk:

Agreed! Likely an error with his Mail settings.

This sounds fishy. All caps are mine. Should that be something like MESSAGE, rather than ACCOUNT? That is, shouldn't it be trying to set the mailbox of a message, rather than the mailbox of an account. Does that make any sense?

I agree it doesn't seem right. The account and mailbox exist, I use them every day and move emails between them manually in Mail.
I'll keep digging.

This might sound silly, but have you tried rebooting? :sweat_smile:

Yes, several times and updated to 12.2.1

That's very odd then and likely beyond my limited AppleScript capabilities. I'd suggest posting over on the Late Night Software forum.

Just to close this properly - the issue is fixed. I was using that mail account to send and receive with no problems but later noted that things like random selection of signatures and setting this account as the default reply account were not working correctly. In the end I deleted the account and re-entered the details. It all appears to work correctly now including the AppleScript. I assume that for some reason the script couldn’t see the account as it was corrupted in some way. Thanks for all the input.

2 Likes