Reputation: 23
Here is the thing:
I'm using AppleScript in Automator to get the clipboard value, and of course it works, but when I want to get multiple separated value, it always returns me only one value on the top。
Here is the step:
on run {input, parameters}
--get the clipboard info
set Storage to get the clipboard
display dialog Storage
return input
end run
I've tried to copy some text_1, text_2 ... manually(command+c, command+v) and then run my AppleScript only, and it turns out the result what I really want like this:
Here is my Script Editor code:
I have to say, due to some limitation I can only use Automator and AppleScript,so is there any solution or suggestion? Here is the "Get Value of Variable" picture Get Value of Variable
Upvotes: 1
Views: 3407
Reputation: 6092
I believe this is a bug in either the Automator Copy To Clipbard
action or AppleScript. Automator actions are often written in Objective-C, and it has some data types that AppleScript doesn't. It looks like the Automator action copies an array to the clipboard, which is something you can do with Objective-C, but not with AppleScript.
My feeling is that AppleScript is the entity at fault here, as the action is doing what it is meant to, and within the Automator context, it wouldn't pose a problem keeping the clipboard's data as an array type. AppleScript likely hasn't catered for this in its implementation of clipboard data handling, and does a poor job of coercing the array or list into plain text, which—as you stated—only contains the first element of the array.
do shell script
commandInstead of:
set Storage to get the clipboard
try:
set Storage to do shell script "pbpaste"
Since the Automator action is probably written in ObjC, it's reasonable to assume that using AppleScriptObjC will give us access to the necessary data types.
Replace your entire AppleScript with this:
use framework "Foundation"
use scripting additions
set Storage to (current application's NSPasteboard's generalPasteboard's ¬
stringForType:(current application's NSPasteboardTypeString)) ¬
as text
display alert Storage
input
variableThe Run AppleScript
action in Automator takes the result of the previous action and stores it in the variable attached to the on run {input, parameters}
handler, namely input
(you can ignore parameters
).
Currently, your workflow actually sends the contents of the clipboard (the output of the Copy To Clipboard
action) directly to the input
variable of your AppleScript.
Therefore, you can replace the entire AppleScript with this:
on run {input, parameters}
set the text item delimiters to linefeed
set Storage to the input as text
display dialog Storage
end run
Any one of these solutions should work, so just choose your preferred method. Number #3 probably makes most sense in your current set up, and is the simplest.
Upvotes: 2