Hi guys,
I’m new to this board, have 15 years experience on Macs, too many years experience on Applescript bu only recently got into ASS.
this si my little puzzle:
I can set up a drag and drop and return the filename/pathname, but I need a way to distinguish between a file and a folder and instruct Finder to take appropriate action.
In a previous desktop droplet script I have used an IF to determine if the pathname ends with “:” to detect a folder but this trick doesn’t seem to work in ASS.
Any suggestions?
Thanks in advance
Paul
I think that ASS’ droplets return POSIX paths… Anyway, if you don’t know if a thing is a posix file or alias or text or what?, then you can use the following:
set f to f as Unicode text
if f does not contain ":" then set f to POSIX file f as Unicode text
set f to f as alias
if (f as text) ends with ":" then --> is folder
return "folder"
else --> is file
return "file"
end if
(where “f” is the unknown thing, a file or folder in posix-path, file path, alias or simple path form)
Thanks JJ,
But… even setting a variable to the POSIX path, for some reason the final “:” is stripped off so there is no difference between a file or a folder
Any other ideas anyone?
cheers,
Paul
Yes, but when you coerce it to alias, the “:” is appended automatically to the path if the item is a folder:
set f to f as alias
Then you can re-check coercing to text again:
if (f as text) ends with ":" then...
tried it JJ but the ‘set f to f as alias’ returns the error that f could not be found -43
Does the following test work for you?
test(alias "DISKNAME:Users:USERNAME:Desktop:cuentas.txt") --> "file"
test("DISKNAME:Users: USERNAME:Desktop:cuentas.txt") --> "file"
test("/Users/USERNAME/Desktop/cuentas.txt") --> "file"
test("/Users/USERNAME/Desktop/cuentas.txt" as POSIX file) --> "file"
test(alias "DISKNAME:Users: USERNAME:Desktop:") --> "folder"
test("DISKNAME:Users: USERNAME:Desktop") --> "folder"
test("/Users/USERNAME/Desktop") --> "folder"
test("/Users/USERNAME/Desktop" as POSIX file) --> "folder"
to test(f)
set f to f as Unicode text
if f does not contain ":" then set f to POSIX file f as Unicode text
set f to f as alias
if (f as text) ends with ":" then --> is folder
return "folder"
else --> is file
return "file"
end if
end test
sighs,
tried that JJ - and every combination and in every case it fails to return the colon at the end of the path. it returns full pathnames with either “/” or “:” delimiters, but not the colon at the end.
I am using 10.3.4 and xcode 1.2, all patches and upgrades applied. I have tried this on my G4 and my iBook with the same result. this is really doing my head in.
thanks for your help andyway JJ
Cheers,
Paul