• 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: Paste Reference in OS 10.4
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Paste Reference in OS 10.4


  • Subject: Re: Paste Reference in OS 10.4
  • From: kai <email@hidden>
  • Date: Sun, 6 Nov 2005 20:57:14 +0000


On 6 Nov 2005, at 03:47, deivy petrescu wrote:


On Nov 4, 2005, at 21:37, kai wrote:


On 4 Nov 2005, at 19:38, email@hidden wrote:

I really miss the paste reference command from the edit menu of Script Editor, it made scripting so much faster. Has this been corrected in OS 10.4?

Evidently not yet (OS 10.4.3) - although it should be possible to cobble together a fair imitation in the meantime...

[snip]

I used to miss it to!
Now, both in Smile and Script Editor, just drag the file to the window. A reference to the file is pasted on the cursor location.
That ought to do it!

Indeed it does, Deivy. Neat trick. :-)

I see that this method places a POSIX path (sans quotation marks) in the script editor. When a multiple selection is dragged to the window, the multiple POSIX paths are placed as separate paragraphs. A POSIX path is more generally useful than a Finder reference (which is obviously of relevance only to Finder). However, from a scripting point of view, it might have been preferable to include quotation marks - and to paste multiple selections as lists. But now I'm just getting picky. ;-)

If the dragged selection contains a folder, a dialog asks for confirmation. Interestingly, although this dialog includes a button marked "Alias", it appears to perform exactly the same function as the "Copy" button. (Looks like it might be an incomplete Cocoa action.)

While Script Editor's original "Paste Reference" command handled multiple selections, my last suggestion didn't. This was simply because, from data extracted from the clipboard, I couldn't come up with a foolproof way of differentiating between similarly named items whose extensions were not displayed (such as "some item.txt", "some item.scpt" or "some item").

Seems to me that a more generally useful approach might be some sort of "Paste Finder Selection As..." command, which cuts out the need to copy or drag from Finder - as well as offering a choice of class for the pasted item(s).

The following script is an example of what I mean. (Since the 'file specification' class tends to lose its magic after text conversion, the script doesn't include it as an option.) As with my previous suggestion, to run this from the Script Menu when Script Editor is frontmost, I saved it in "/Users/UserName/Library/Scripts/ Applications/Script Editor/Paste Finder Selection As....scpt". (Again, don't forget that running the script directly from a Script Editor window will normally result in a paste to that window.)

------------------

property pasteList : {"alias", "Finder reference", "path", "POSIX path", "URL"}
property pasteType : pasteList's item 1


on listToText(l)
	try
		l's t
	on error t
		set tid to text item delimiters
		set text item delimiters to "{"
		set t to t's text from text item 2 to -1
		set text item delimiters to "}"
		set t to t's text 1 thru text item -2
		set text item delimiters to tid
		t
	end try
end listToText

to choosePasteType()
	tell application "Script Editor" to tell (choose from list pasteList ¬
		with prompt "Paste Finder selection as:" default items ¬
		pasteType OK button name "Paste")
		if it is false then error number -128
		set pasteType to item 1
	end tell
end choosePasteType

to convertList(l, c)
	tell choosePasteType() to if it is "alias" then
		repeat with i in l
			set i's contents to i as alias
		end repeat
	else if it is "path" then
		repeat with i in l
			set i's contents to i as Unicode text
		end repeat
	else if it is "POSIX path" then
		repeat with i in l
			set i's contents to (i as Unicode text)'s POSIX path
		end repeat
	else if it is "URL" then
		tell application "Finder" to repeat with i in l
			set i's contents to i's URL
		end repeat
	end if
	if c is 1 then return listToText(l)
	"{" & listToText(l) & "}"
end convertList

to pasteFrom(l)
	set c to count l
	tell application "Script Editor"
		activate
		if c is 0 or (count documents) is 0 then return beep
		set r to the clipboard as record
		set the clipboard to my convertList(l, c)
		tell application "System Events" to keystroke "v" using command down
		delay 0.2
		set the clipboard to r
	end tell
	0 -- Script Menu bug workaround (to save script properties)
end pasteFrom

tell application "Finder" to my pasteFrom(selection)

------------------

---
kai


_______________________________________________ Do not post admin requests to the list. They will be ignored. Applescript-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Paste Reference in OS 10.4
      • From: kai <email@hidden>
References: 
 >Paste Reference in OS 10.4 (From: email@hidden)
 >Re: Paste Reference in OS 10.4 (From: kai <email@hidden>)
 >Re: Paste Reference in OS 10.4 (From: deivy petrescu <email@hidden>)

  • Prev by Date: Scripting Mail signatures in 10.4.3
  • Next by Date: Re: speed test, anyone?
  • Previous by thread: Re: Paste Reference in OS 10.4
  • Next by thread: Re: Paste Reference in OS 10.4
  • Index(es):
    • Date
    • Thread