• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scriptable multi-clipboard utility?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scriptable multi-clipboard utility?


  • Subject: Re: Scriptable multi-clipboard utility?
  • From: "koenig.yvan" <email@hidden>
  • Date: Sun, 09 Mar 2014 11:16:48 +0100


Le 09/03/2014 à 04:54, Michael Grant <email@hidden> a écrit :

For whatever reason, my version was failing when I tried to use the test 'if myChoice is false', i.e. the simple boolean. I wasn't getting consistent results trying to use that weird chevron class notation {«class fals»:false} either. And for my purposes, I'd rather not have the complication at runtime of allowing multiple selections, so for me the only reason not to use the text coercion would be that my version will fail if the chosen paragraph really *is* the text "false". 

As for the try block, this morning I was focused on text, but of course the choose from list line does throw an error if the original clipboard content can't be coerced to text. So in what I've got now, I restored the try block and also placed the line that sets the clipboard text to a variable inside it.

I also adopted Yvan's 'file of first process' to get the active app reference.

Chris, you mentioned the risk of leaving the dialog hanging if the user clicks away or switches applications, but not activating System Events doesn't actually prevent that, does it?

One more remaining flaw is that the original clipboard content is not fully restored if it starts out as data other than plain text but that can be coerced to text. I did a little bit of playing around with storing the uncoerced content to a variable before getting the text, but that failed with a file copied in the Finder and with the styled text of the compiled script itself from AppleScript Editor. Since the multi-clipboard utilities that started the whole thread do exist, there must be some way to restore the full content, at least via ASObjC if not plain AS, but for me I don't think it's worth the time investment to look for a solution.

For reference, here's my current version (which omits Yvan's multiple selection option and Chris's more complete error code):

tell application "System Events"
set frontApp to (file of first process whose frontmost is true) as text


try
set fullClipText to (the clipboard as text)
activate
set myChoice to ((choose from list (paragraphs of fullClipText)) as text)
on error
set myChoice to "false"
end try
end tell

tell application frontApp
activate
if myChoice is not "false" then
set the clipboard to myChoice
tell application "System Events" to keystroke "v" using {command down}
delay 1
set the clipboard to fullClipText
end if
end tell


Michael

I'm really puzzled because I never got any kind of problem with the test upon the boolean false.
In your code, it's the instruction 
set fullClipText to (the clipboard as text)
which may issue an error if the clipboard doesn't contain text data.
I tested with :

try
set maybe to true


choose from list {"azerty", "qsdfg", "wxcvb"}
on error
set maybe to false
end try
maybe

Clicking the Cancel button or hitting the Escape key changes nothing, maybe remains true which means that doing that doesn't issue an error.

Keeping you choice of coercing as text, I would use an edited version :

tell application "System Events"
set frontApp to (file of first process whose frontmost is true) as text
end tell
try
set fullClipText to (the clipboard as text)
tell application "SystemUIServer" to set myChoice to ((choose from list (paragraphs of fullClipText)) as text)
on error
set myChoice to "false"
end try

if myChoice is not "false" then
tell application frontApp
activate
set the clipboard to myChoice
tell application "System Events" to keystroke "v" using {command down}
delay .1
set the clipboard to fullClipText
end tell
end if


I guess that fullClipText can't be huge to fit in a choose from list dialog so the delay may be reduced to delay.1 with no problem.


Yvan KOENIG (VALLAURIS, France) dimanche 9 mars 2014 11:16:43


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Scriptable multi-clipboard utility?
      • From: Michael Grant <email@hidden>
References: 
 >Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: "koenig.yvan" <email@hidden>)
 >Re: Scriptable multi-clipboard utility? (From: Michael Grant <email@hidden>)

  • Prev by Date: Re: build a list of mailboxes
  • Next by Date: Re: Scriptable multi-clipboard utility?
  • Previous by thread: Re: Scriptable multi-clipboard utility?
  • Next by thread: Re: Scriptable multi-clipboard utility?
  • Index(es):
    • Date
    • Thread