0

In applescript I use the following code to set the clipboard to a list (array): set the clipboard to {"4", "4", "5"}

Is it possible to assign the items of the list in the clipboard to a bash array? In applescript, the code for assigning the list items (from the clipboard) to a variable looks like this: set theList to list of (the clipboard). What would be the bash equivalent for this code?

Thank you!

  • Accessing the clipboard in bash is done with `pbcopy`, which reads stdin and `pbpaste`, which writes to stdout. I don't know much more though. – gurkensaas Dec 28 '21 at 15:47
  • Thanks, @gurkensaas! I've quit trying to transfer the AS (AppleScript) list (array) to Bash. I believe that the only option available is to store the elements of the AS list in the clipboard as string. Like this: `set the clipboard to items of theList as string` (items must contain a line break at the end, so that they are pasted in Bash on separate lines). In Bash, I use this code: `clipboard="$(pbpaste)"` to put the content of the clipboard in a var. How to make array from "clipboard" var: https://stackoverflow.com/questions/10586153/how-to-split-a-string-into-an-array-in-bash – Alin Teodor Catană Dec 29 '21 at 13:50
  • Seems good, if you manage to do it, consider posting an answer to your own question. – gurkensaas Dec 29 '21 at 19:07

1 Answers1

0

My answer to my question is as it follows. There's no Bash equivalent to set theList to list of (the clipboard). But, there's this code that puts the content of the clipboard into a variable called "clipboard" (provided that the clipboard contains items separated by space or on separate lines).

#!/bin/bash

clipboard="$(pbpaste)" # get the content of the clipboard
theList=( $clipboard ) # make an array from the clipboard content

echo ${theList[1]} # proof that "theList" is an array