• 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: how to coerce a built-up path?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to coerce a built-up path?


  • Subject: Re: how to coerce a built-up path?
  • From: Walter Ian Kaye <email@hidden>
  • Date: Tue, 9 Dec 2003 14:59:11 -0800

At 01:52p -0800 12/09/2003, Mark Dawson didst inscribe upon an electronic papyrus:

How do you coerce a built-up file/path into a file or alias type?

set theFolder to (choose folder with prompt "Pick the folder")
set fromFile to theFolder & "duplicate"

set fromFile to (theFolder as string) & "duplicate"

set toBundle to theFolder & bundleName

--likewise:
set toBundle to (theFolder as string) & bundleName

display dialog theFolder & "--" & fromFile & "--" & toBundle
copyFile (fromFile as file) to (toBundle as file)

When I run the above lines, I get an error, "can't make {alias "backup2:x:output:", "duplicate"} into a file."

Concatenation takes the datatype on the left as precedence... I mean, it will coerce the datatype on the right if it can; otherwise it will form a list.

Since AS cannot turn "duplicate" into an alias and concatenate to another alias (because that's invalid in more ways than one), you got yourself a list.

To concatenate a string ("duplicate") onto an alias, you must first coerce the alias into a string. Thus the code I posted above.

You may wish to use 'as Unicode text' instead of 'as string' to make the code more OS X savvy.

To turn the resulting string into an alias -- assuming that it points to a preexisting file (or folder) -- you can do either of the following:

alias fromFile
fromFile as alias

If the file does not exist, then you would need to use a file spec:

file fromFile
fromFile as file specification


HTH,
-Walter
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

References: 
 >how to coerce a built-up path? (From: Mark Dawson <email@hidden>)

  • Prev by Date: Re: Screen capture
  • Next by Date: RE: Screen capture
  • Previous by thread: Re: how to coerce a built-up path?
  • Next by thread: Re: how to coerce a built-up path?
  • Index(es):
    • Date
    • Thread