• 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: simple duplicate script question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: simple duplicate script question


  • Subject: Re: simple duplicate script question
  • From: kai <email@hidden>
  • Date: Wed, 14 Mar 2007 01:07:53 +0000


On 12 Mar 2007, at 14:45, Doug McNutt wrote:

At 14:19 +0100 3/12/07, Jacco Rens wrote:
tell application "Finder"
	try
		set theDocumentsFolder to (path to documents folder)
		set theWorkFolder to (path to desktop folder)
		set ThisSjabloon to theDocumentsFolder & "sjabloon" as alias
		copy ThisSjabloon to theWorkFolder
	end try
end tell

I sympathize. I can never figure out AppleScript syntax either. It's all guesswork.


I think the concatenation (theDocumentsFolder & "sjabloon") is not returning something that is recognizable as a fully qualified file name.

That's right, Doug. While other issues regarding the script have already been discussed, this one probably warrants a closer look.


According to AppleScript's concatenation rules, the result of a concatenation depends on the type of the left hand operand. If it's text or a record, AppleScript tries to coerce the value of the right- hand operand to match that of the left. If it's some other type, the result is a list.

So, because Scripting Additions' 'path to…' command returns an alias, rather than a text path, the result of the above concatenation is a list: {alias "startupdisk:Users:username:Documents:", "sjabloon"}. And since a list can't be coerced to alias, the coercion fails with an error number -1700 (which is obviously masked by the try block).

Coercion of the folder alias to (Unicode) text first, as employed in Yvan's script, allows the folder's path to be concatenated with the target item's name. Assuming the item exists, the coercion of the resulting text path to alias (though probably not essential in this context) should, along with the subsequent duplicate operation, then succeed.

Incidentally, an alternative approach to path/name concatenation is to simply use a Finder reference:

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

set theDocumentsFolder to path to documents folder
set theWorkFolder to path to desktop folder
tell application "Finder" to tell folder theDocumentsFolder's ¬
	item "sjabloon" to if exists then duplicate to theWorkFolder

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

---
kai


_______________________________________________ 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
References: 
 >simple duplicate script question (From: Jacco Rens <email@hidden>)
 >Re: simple duplicate script question (From: KOENIG Yvan <email@hidden>)
 >Re: simple duplicate script question (From: Jacco Rens <email@hidden>)
 >Re: simple duplicate script question (From: Doug McNutt <email@hidden>)

  • Prev by Date: Re: Accesing menu bar items.
  • Next by Date: Re: Encoded file URL to Mac or Posix path...
  • Previous by thread: Re: simple duplicate script question
  • Next by thread: Re: Re: simple duplicate script question (solved)
  • Index(es):
    • Date
    • Thread