1

I have an AppleScript .app file that creates a list variable based on a website's HTML data. The number of items in this list varies based on the unique HTML data that is downloaded on every iteration, and can range from 1 to 50.

I ultimately want to display the contents of each line as its own drop-down menu in one dialog. I am using the external script library, Dialog Toolkit, to accomplish this, which requires the declaration of many additional variables.

Dialog Toolkit works differently than choose from list, for example. The choose from list dialog will automatically adjust its size to add a new line for each list item. But, for a Dialog Toolkit dialog, you instead must separately define (i.e., as its own unique variable) every drop-down menu that is needed. If you don't, zero drop-down menus will exist in the dialog.

Hence, 50 if statements are needed to ensure that the dialog contains all drop-down menus, like so:

repeat with i from 1 to (count of theList)
        if (i is 1) then
            set {dropdown1} to create labeled dropdown (item i of theList)
        else if (i is 2) then
            set {dropdown2} to create labeled dropdown (item i of theList)
        i if (i is 3) then
            set {dropdown3} to create labeled dropdown (item i of theList)
        else if (i is 4) then

        ...

        else if (i is 50) then
            set {dropdown50} to create labeled dropdown (item i of theList)
        end if
end repeat

-- Note: The above code snippet is a very stripped down version of my code.

Is it possible for an AppleScript to create, on its own, new variables that have formulaic titles?

Here is the type of thing that I desire:

repeat with i from 1 to (count of theList)
    set {(("dropdown" & i) as variable)} to create labeled dropdown (item i of theList)
end repeat

OS X El Capitan, version 10.11.6.


2
  • I do not believe that which you desire is possible. Commented Jul 15, 2017 at 12:08
  • It's possible to create multiples labeled dropdowns without needing 50 defined variables and 50 else if conditions. I do not answer because it will not answer your original question. If you want an example of this script, change the title of the question, or post another question.
    – jackjr300
    Commented Aug 21, 2017 at 23:52

2 Answers 2

1

This is an example of using a list to achieve something similar to what you are trying to do, I think:

    set varList to {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}

    tell application "Google Chrome"
        count every tab of window 1
        set tabCount to result
        set counterOne to 1
        repeat tabCount times
            get URL of tab counterOne of window 1
            set item counterOne of varList to result
            set counterOne to counterOne + 1
        end repeat
    end tell

    tell application "Google Chrome"
        make new window
        set counterOne to 1
        repeat tabCount times
            set tabVari to item counterOne of varList
            open location tabVari
            set counterOne to counterOne + 1
        end repeat
    end tell
0

This is only an answer because I need to include a Script. It might be useful to you to know that you can still write self modifying code in AppleScript.

Here's an example that adds a "beep 2" as its first line every time it is run. You're using a toolkit I'm unfamiliar with, and it might not appreciate having its code changed out from under it, then again, you might get away with it.

    -- Self Modifying code
-- BP 2006
-- Still works in 2019

-- Just a Demo
-- Run this code twice and look at the first line It will change

set mystring to "beep 2"

--display dialog mystring

tell application "Script Editor"
    activate
    set text of front document to mystring & "\r" & text of front document -- prepend the line as a new line
end tell

tell application "Script Editor"
    activate
end tell

Language writers worked hard to get rid of self modifying code back on the 80's, but it's still there in AppleScript, and sometimes you can do useful tricks with that fact.

You must log in to answer this question.

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