1

I'm trying to make a little scriptlet to easily display in a copy/pasteable format, my crypto wallet addresses. However I'm having problems with proper usage of "choose from list". The error I get is "The variable pasteThis is not defined", my code is below, crypto addresses redacted for obvious reasons.

on run
    set walletChoices to {"ETH", "DOGE", "XMR", "BTC"}
    set whichWallet to choose from list walletChoices with prompt "Which wallet do you need?" default items {"ETH"}
    if whichWallet is "ETH" then
        set walletExpanded to "Ether"
        set pasteThis to "ethAddr"
    else if whichWallet is "XMR" then
        set walletExpanded to "Monero"
        set pasteThis to "xmrAddr"
    else if whichWallet is "DOGE" then
        set walletExpanded to "Dogecoin"
        set pasteThis to "dogeAddr"
    else if whichWallet is "BTC" then
        set walletExpanded to "Bitcoin"
        set pasteThis to "btcAddr"
    end if
    display dialog "Here's your " & whichWallet & " wallet, as requested!" default answer pasteThis buttons {"OK"} default button "OK"
end run

Can someone please tell me what I'm doing wrong and how to use this properly?

2 Answers 2

3

From choose from list in the AppleScript Language Guide:

Result
If the user clicks the OK button, returns a list of the chosen number and/or text items; if empty selection is allowed and nothing is selected, returns an empty list ({}). If the user clicks the Cancel button, returns false.


So, in your if statement, if whichWallet is "ETH" then, the "ETH" etcetera is text, not a list, {"ETH"} and why set pasteThis to ... never occurs.

Either test against a list, list item, or coerce what's returned by choose from list to text.

If you change:

set whichWallet to choose from list walletChoices with prompt "Which wallet do you need?" default items {"ETH"}

To:

set whichWallet to (choose from list walletChoices with prompt "Which wallet do you need?" default items {"ETH"}) as text

Then the rest of the code, as coded, will work.

Otherwise you can use the example shown in the choose from list link.

Or you can test against a list:

Change:

if whichWallet is "ETH" then

To:

if whichWallet is {"ETH"} then

Doing the same for the rest of the list items in the else if whichWallet is ... statements.

Notes:

The changes mentioned herein work with the the suggested changes to the code of the question as the choose from list command by default does not allow multiple selections and multiple selections allowed true has not been included as part of the choose from list command.

Based on what it appears the OP is trying to do, this is a non-issue, however, I'm mentioned it because if it was implemented then a different approach would need to be used dealing with multiple list items returned in the list. That is, one would need to loop thru the list returned and act on each list item.

4
  • Thank you guys!!! It's finally working how I wanted it to!!! And I learned something while NOT righteously stoned, so it should actually stick and benefit me in the future! XD XD Amazing how just simply wrapping it with {} and adding "as text" was the cure to my woes!
    – RobinBanks
    Jul 23, 2021 at 6:54
  • Now I just set a keyboard maestro macro to be triggered from the global pallet that runs this script and all my wallet addresses are just a couple clicks away in any app necessary
    – RobinBanks
    Jul 23, 2021 at 7:03
  • @RobinBanks, RE: "Amazing how just simply wrapping it with {} and adding "as text" was the cure to my woes!" -- It was one or the other, not both, and with adding as text the whole choose from list command has to be wrapped in parentheses. Please reread the answer. Jul 23, 2021 at 12:02
  • 1
    @RobinBanks, Appreciate the thanks, however, please have a look at: What should I do when someone answers my question? and if you feel so inclined to mark my answer as the accepted answer that would be appreciated, thanks. Jul 23, 2021 at 12:04
0

replace all if whichWallet is with if whichWallet contains

If you plan to coerce the list returned from your prompt to string, this change should be resilient to multiple list options being concatenated into a single text (if you allowed multiple selections that is.)

The problem with this method is that, since the choices coerced to text might create a string that contains a choice that was never selected by the user as a result of concatenation, it becomes sensitive to the order of your statements and whether you code it to stop or continue.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .