Search code examples
applescriptcolor-picker

AppleScript: Set default colour for ColourPicker from variable


I'm trying to call the ColourPicker from AppleScript using a variable as the default colours. However I cannot get this to work.

To illustrate my issue I wrote a little code sample of what I tried, which does not work.

set defaultColour to do shell script "echo {65535, 0, 65535}"

set RGB to (choose color default color defaultColour)
##set RGB to (choose color default color {65535, 0, 65535})

I included the working, default code for reference.

Thanks in advance for your help.


Solution

  • Using run script command you can always convert the "text-form integers list " directly to usual integers list. So, repeat loop no need at all:

    set defaultColour to "{65535, 0, 65535}"
    
    set RGB to choose color default color (run script defaultColour)
    

    For none-secure text content from the internet I would use the text items delimiters method, like here:

    set defaultColour to "{65535, 0, 65535}"
    
    set ATID to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {"{", ", ", "}"}
    tell defaultColour to set defaultColour to {text item 2 as integer, text item 3 as integer, text item 4 as integer}
    set AppleScript's text item delimiters to ATID
    
    set RGB to choose color default color defaultColour