Thursday, July 9, 2020

#1 2020-06-15 04:00:48 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Can't Convert Server Finder Reference to Alias

I have a little automator script that duplicates a folder then does some processing within the new duped folder. I'm running into an issue where if I'm duplicating locally I can get a Alias path but if I duplicate to the server I get an error. Here are modified snippets...

Local:

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Users/Me/Desktop/DestinationFolder"

tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
end tell

return newItem as alias

This returns:

alias "MacintoshHD:Users:ME:Desktop:DestinationFolder:MyFolder:"



Server:

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
end tell

return newItem as alias

This returns:

“Can’t make «class cfol» "MyFolder" of «class cfol» "DestinationFolder" of «class cfol» "To" of «class cfol» "Directory" of «class cdis» "Server" of application "Finder" into type alias.”


The only difference is the destination folder is on the server. Any ideas why this is happening and how to fix? Thanks.

Browser: Safari 537.36
Operating System: macOS 10.14


Filed under: applescript, Finder

Offline

 

#2 2020-06-15 04:09:22 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

Please, for readers like me which don't use server, may you post what is returned by:

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
   properties of newItem
end tell

It may help to understand what strikes.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 16 juin 2020 00:08:30

Offline

 

#3 2020-06-15 04:37:39 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

I get an error when I do that:

Finder got an error: Can’t get disk "Server".



A little more info:

When I

return newItem

I get this..

Local

folder "MyFolder" of folder "DestinationFolder" of folder "Desktop" of folder "Me" of folder "Users" of startup disk of application "Finder"


Server

folder "MyFolder" of folder "DestinationFolder" of folder "To" of folder "Directory" of disk "Server" of application "Finder"


Also, before upgrading to Mojave it was working fine.

Offline

 

#4 2020-06-17 07:32:30 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5239

Re: Can't Convert Server Finder Reference to Alias

A puzzling problem.  hmm

The script works fine for me on my Mojave machine, both in Script Editor and in the Automator application, duplicating one folder to another on my El Capitan machine.

Your error message contains class enums instead of the Finder keywords, so maybe they're not being recognised as belonging to the Finder. Have you tried putting the coercion line inside the Finder 'tell' statement?

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
   return newItem as alias
end tell


NG

Offline

 

#5 2020-06-17 08:22:59 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

foxbot wrote:

I get an error when I do that:

Finder got an error: Can’t get disk "Server".



Are you sure that the server was active when you got that ?
It seems that it doesn't match with what you get when you issue

return newItem


folder "MyFolder" of folder "DestinationFolder" of folder "To" of folder "Directory" of disk "Server" of application "Finder"



I don't use server so I can't test.
What would be returned by :

Applescript:

tell application "Finder"
   name of every disk
   URL of every disk
end tell

Here the log history is :

Applescript:


Don't click [Open this Scriplet in your Editor:]
Here is just a log history
tell application "Finder"
   get name of every disk
       --> {"Box", "SSD 1000", "home", "net", "vm"}
   get URL of every disk
       --> {"file:///Users/**********/Box/", "file:///", "file:///home/", "file:///net/", "file:///private/var/vm/"}
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 17 juin 2020 16:22:54

Offline

 

#6 2020-06-17 01:10:18 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

Your error message contains class enums instead of the Finder keywords, so maybe they're not being recognised as belonging to the Finder. Have you tried putting the coercion line inside the Finder 'tell' statement?

It had the same behavior. Worked as you'd expect locally and returned the same error server side.


Are you sure that the server was active when you got that ?

Yes, server was up and running.


I don't use server so I can't test.
What would be returned by :

Applescript:

tell application "Finder"
name of every disk
URL of every disk
end tell

Returns:

{"MacintoshHD", "home", "net", "vm"}

{"file:///", "file:///home/", "file:///net/", "file:///private/var/vm/"}


Is there another way to get a reference to the duplicated items? I need to process the folders and files within the duped folder and I don't know how to do it if I can't get the path. Thanks again!

Offline

 

#7 2020-06-17 02:04:21 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

foxbot wrote:


I don't use server so I can't test.
What would be returned by :

Applescript:

tell application "Finder"
name of every disk
URL of every disk
end tell

Returns:

{"MacintoshHD", "home", "net", "vm"}

{"file:///", "file:///home/", "file:///net/", "file:///private/var/vm/"}


Thank you. This time I'm really puzzled.

According to what I read in the Finder's dictionary:
disk n [inh. container > item] : A disk
properties
id (integer, r/o) : the unique id for this disk (unchanged while disk remains connected and Finder remains running)
capacity (double integer, r/o) : the total number of bytes (free or used) on the disk
free space (double integer, r/o) : the number of free bytes left on the disk
ejectable (boolean, r/o) : Can the media be ejected (floppies, CDs, and so on)?
local volume (boolean, r/o) : Is the media a local volume (as opposed to a file server)?


I assumed that Server would be returned among the available disks.

Is there another way to get a reference to the duplicated items? I need to process the folders and files within the duped folder and I don't know how to do it if I can't get the path. Thanks again!



You may use something like :

Applescript:

use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

set myItem to "/Volumes/Server/Directory/To/MyFolder" -- MUST be a POSIX Path
set destinationFolder to "/Volumes/Server/Directory/To/DestinationFolder" -- MUST be a POSIX Path

set myItem to current application's NSString's stringWithString:myItem -- ADDED
set destinationFolder to current application's NSString's stringWithString:destinationFolder -- ADDED
set fileManager to current application's NSFileManager's defaultManager()
-- extract the name of the item to duplicate
set sourceName to myItem's lastPathComponent()
-- build the path of the copied item
set newPath to destinationFolder's stringByAppendingPathComponent:sourceName
-- check if the copied item already exists
set isAvailable to fileManager's fileExistsAtPath:(newPath as boolean)
if not isAvailable then -- it doesn't exist so copy it
   set {theResult, theError} to fileManager's copyItemAtPath:myItem toPath:newPath |error|:(reference)
end if
-- If ou executed for the 2nd time this instruction
set isAvailable to fileManager's fileExistsAtPath:(newPath as boolean)
-- isAvailable will be set to true

For more info about ASObjC, download Shane Stanley's "Everyday AppleScriptObjC" from
<https://macosxautomation.com/applescrip … _book.html>

On my side I never used ASObjC upon servers but you may execute the proposed script with no risk.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mercredi 17 juin 2020 22:03:16

Added two forgotten instructions

Last edited by Yvan Koenig (2020-06-18 04:50:43 am)

Offline

 

#8 2020-06-17 03:24:58 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

I'll try that and report back. Thanks Yvan!

Offline

 

#9 2020-06-19 04:23:57 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

Back to your original code.
If I run a similar code on local volume with a non available destination folder:

Applescript:

--set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
--set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"
set myItem to (path to desktop as string) & "pour Musée"
set destinationFolder to (path to documents folder as string) & "unavailableDestinationFolder"
tell application "Finder"
   set newItem to duplicate myItem as alias to folder destinationFolder
end tell

return newItem as alias

The script enter what resemble to an infinite loop and I must relaunch the Finder to exit it.
May I assume that you got the described error when the target folder is unavailable ?
It would not be the first time where we receive an error message which doesn't match the real problem.

For local volumes, I would be forced to use an enhanced script:

Applescript:

--set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
--set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"
set myItem to (path to desktop as string) & "pour Musée"
set destinationFolder to (path to documents folder as string) & "unavailableDestinationFolder"
tell application "Finder"
   if exists folder destinationFolder then
       set newItem to duplicate myItem as alias to folder destinationFolder
   else
       error "the folder “" & destinationFolder & "” is not available"
   end if
end tell

return newItem as alias

Given the way items are defined in your script it would be useful to edit your script as :

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

tell application "Finder"
   if exists destinationFolder then
       set newItem to duplicate myItem to destinationFolder
   else
       error "The folder “" & destinationFolder & "” is not available"
   end if
end tell

return newItem as alias

With ASObjC it's easy to get rid of that.

Applescript:

use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

-- Yvan KOENIG (VALLAURIS, France) 19 juin 2020 12:20:33

set origItem to (path to desktop as string) & "pour Musée" -- Exists on my machine, edit to point to an existing item on your machine
set destFolder to (path to documents folder as string) & "unavailableFolder" -- Deliberately missing folder

if not (my itemExistsAtPath:origItem) then error "“" & origItem & "” is unavailable" number -1728

my createFolder:destFolder -- If destFolder is unavailable, try to create it. May return an error

-- case 1
try
   my duplicateFileAt:origItem toFolder:destFolder
on error
   log "non fatal error"
   -- The target item already exists. I assume that we may continue without doing anything.
end try
-- case 2
-- If the item already exists in destFolder, copy the new one appending a dateTime stamp to its name
my duplicateStampedItemAt:origItem toFolder:destFolder

-- case 3
-- If the item already exists in destFolder, delete the existing item and copy the new one
my duplicateItemAtWithReplacing:origItem toFolder:destFolder

#=====

on itemExistsAtPath:HfsPath
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXitem to current application's NSString's stringWithString:(POSIX path of HfsPath)
   return fileManager's fileExistsAtPath:POSIXitem
end itemExistsAtPath:

#=====

on createFolder:destFolder -- here, destFolder is an Hfs path
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set fileManager to current application's NSFileManager's defaultManager()
   if not (fileManager's fileExistsAtPath:POSIXdest) then
       -- the destination folder doesn't exist, create it
       set destURL to current application's NSURL's fileURLWithPath:POSIXdest
       set {theResult, theError} to fileManager's createDirectoryAtURL:destURL withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
       if (theResult as boolean) is false then
           error (theError's localizedDescription() as string)
       end if
   end if
end createFolder:

#=====

on duplicateFileAt:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   if (theResult as boolean) is false then
       error (theError's localizedDescription() as string)
   end if
end duplicateFileAt:toFolder:

#=====

on duplicateItemAtWithReplacing:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   if fileManager's fileExistsAtPath:theNewPath then
       -- delete the existing item
       fileManager's removeItemAtPath:theNewPath |error|:(reference)
   end if
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   if (theResult as boolean) is false then
       error (theError's localizedDescription() as string)
   end if
end duplicateItemAtWithReplacing:toFolder:

#=====

on duplicateStampedItemAt:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   if fileManager's fileExistsAtPath:theNewPath then
       set thePathNoExt to theNewPath's stringByDeletingPathExtension()
       set stamp to my buildStamp()
       set theExtension to POSIXsource's pathExtension()
       -- insert the stamp in the file name so it will not duplicate
       set theNewPath to (thePathNoExt's stringByAppendingString:stamp)'s stringByAppendingPathExtension:theExtension
   end if
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   if (theResult as boolean) is false then
       error (theError's localizedDescription() as string)
   end if
end duplicateStampedItemAt:toFolder:

#=====

on buildStamp()
   tell (current date) to return "_" & (((its year) * 10000 + (its month) * 100 + (its day)) as string) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as string)
end buildStamp

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 19 juin 2020 11:51:00

Last edited by Yvan Koenig (2020-06-19 12:57:51 pm)

Offline

 

#10 2020-06-20 10:39:05 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

foxbot wrote:

I get an error when I do that:

Finder got an error: Can’t get disk "Server".



A little more info:

When I

return newItem

I get this..

Local

folder "MyFolder" of folder "DestinationFolder" of folder "Desktop" of folder "Me" of folder "Users" of startup disk of application "Finder"


Server

folder "MyFolder" of folder "DestinationFolder" of folder "To" of folder "Directory" of disk "Server" of application "Finder"


Also, before upgrading to Mojave it was working fine.




May it be that the folder /Directory/To/DestinationFolder/ was unavailable on the Server ?
May you try to execute:

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set POSIXDest to "/Volumes/Server/"
set level1 to "Directory/"
set destinationFolder1 to POSIX file ("/Volumes/Server/" & level1)
set level2 to "To/"
set destinationFolder2 to POSIX file ("/Volumes/Server/" & level1 & level2)
set level3 to "DestinationFolder/"
set destinationFolder to POSIX file ("/Volumes/Server/" & level1 & level2 & level3)

tell application "Finder"
   exists destinationFolder1
   log result
   exists destinationFolder2
   log result
   exists destinationFolder
   log result
   set newItem to duplicate myItem to destinationFolder
   return newItem as alias
end tell

Of course you will have to replace "Directory", "To", MyFolder" and  "DestinationFolder" by real names of subfolders.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 20 juin 2020 18:38:50

Offline

 

#11 2020-06-22 11:00:23 am

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

Hi Yvan, I really appreciate all of the suggestions. I got slammed at work and can't dig in until later this week.

I will confirm though that the server is definitely available. In fact my source folder is on the server. Also I should add that the duplicate command works, the source folder gets duplicated into the destination folder. Assigning the newItem variable is where it fails and I get the error.

Last edited by foxbot (2020-06-22 11:00:47 am)

Offline

 

#12 2020-06-22 01:11:20 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

If it's only that, you may add some instructions at the end of the handlers.

Applescript:

use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

-- Yvan KOENIG (VALLAURIS, France) 22 juin 2020 22:05:33

property wantFurl : true
-- if true, the duplicate handler return «class furl» object
-- if false, the duplicate handler return POSIXPath object

set origItem to (path to desktop as string) & "pour Musée" -- Exists on my machine, edit to point to an existing item on your machine
set destFolder to (path to documents folder as string) & "unavailableFolder" -- Deliberately missing folder

if not (my itemExistsAtPath:origItem) then error "“" & origItem & "” is unavailable" number -1728

set newItem to my createFolder:destFolder -- If destFolder is unavailable, try to create it. May return an error
log newItem --> "/Users/yvankoenig/Documents/unavailableFolder/"
--> file "SSD 1000:Users:yvankoenig:Documents:unavailableFolder:"

-- case 1
set newItem to my duplicateFileAt:origItem toFolder:destFolder
log newItem --> "/Users/yvankoenig/Documents/unavailableFolder/pour Musée"
--> file "SSD 1000:Users:yvankoenig:Documents:unavailableFolder:pour Musée:"

-- case 2
-- If the item already exists in destFolder, copy the new one appending a dateTime stamp to its name
set newItem to my duplicateStampedItemAt:origItem toFolder:destFolder
log newItem --> "/Users/yvankoenig/Documents/unavailableFolder/pour Musée_20200622_214650"
--> file "SSD 1000:Users:yvankoenig:Documents:unavailableFolder:pour Musée_20200622_214942:"

-- case 3
-- If the item already exists in destFolder, delete the existing item and copy the new one
set newItem to my duplicateItemAtWithReplacing:origItem toFolder:destFolder
log newItem --> "/Users/yvankoenig/Documents/unavailableFolder/pour Musée"
--> file "SSD 1000:Users:yvankoenig:Documents:unavailableFolder:pour Musée:"

#=====

on itemExistsAtPath:HfsPath
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXitem to current application's NSString's stringWithString:(POSIX path of HfsPath)
   return fileManager's fileExistsAtPath:POSIXitem
end itemExistsAtPath:

#=====

on createFolder:destFolder -- here, destFolder is an Hfs path
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set fileManager to current application's NSFileManager's defaultManager()
   if not (fileManager's fileExistsAtPath:POSIXdest) then
       -- the destination folder doesn't exist, create it
       set destURL to current application's NSURL's fileURLWithPath:POSIXdest
       set {theResult, theError} to fileManager's createDirectoryAtURL:destURL withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
       if (theResult as boolean) is false then
           error (theError's localizedDescription() as string)
       end if
   end if
   if wantFurl then
       return (current application's NSURL's fileURLWithPath:POSIXdest) as «class furl»
   else
       return POSIXdest as string
   end if
end createFolder:

#=====

on duplicateFileAt:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   
   if (theResult as boolean) is false then
       if theError's code() as integer ≠ 516 then error (theError's localizedDescription() as string)
   end if
   if wantFurl then
       return (current application's NSURL's fileURLWithPath:theNewPath) as «class furl»
   else
       -- log "case 1 : " & theNewPath as string
       return theNewPath as string
   end if
end duplicateFileAt:toFolder:

#=====

on duplicateStampedItemAt:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   if fileManager's fileExistsAtPath:theNewPath then
       set thePathNoExt to theNewPath's stringByDeletingPathExtension()
       set stamp to my buildStamp()
       set theExtension to POSIXsource's pathExtension()
       -- insert the stamp in the file name so it will not duplicate
       set theNewPath to (thePathNoExt's stringByAppendingString:stamp)'s stringByAppendingPathExtension:theExtension
   end if
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   if (theResult as boolean) is false then
       error (theError's localizedDescription() as string)
   end if
   if wantFurl then
       return (current application's NSURL's fileURLWithPath:theNewPath) as «class furl»
   else
       -- log "case 2 : " & theNewPath as string
       return theNewPath as string
   end if
end duplicateStampedItemAt:toFolder:

#=====

on duplicateItemAtWithReplacing:sourcePath toFolder:destFolder -- here, sourcePath is an alias and destFolder is an Hfs path
   set fileManager to current application's NSFileManager's defaultManager()
   set POSIXsource to current application's NSString's stringWithString:(POSIX path of sourcePath)
   set POSIXdest to current application's NSString's stringWithString:(POSIX path of destFolder)
   set theNewPath to POSIXdest's stringByAppendingPathComponent:(POSIXsource's lastPathComponent())
   set fileManager to current application's NSFileManager's defaultManager()
   if fileManager's fileExistsAtPath:theNewPath then
       -- delete the existing item
       fileManager's removeItemAtPath:theNewPath |error|:(reference)
   end if
   set {theResult, theError} to fileManager's copyItemAtPath:POSIXsource toPath:theNewPath |error|:(reference)
   if (theResult as boolean) is false then
       error (theError's localizedDescription() as string)
   end if
   if wantFurl then
       set destURL to current application's NSURL's fileURLWithPath:theNewPath
       return destURL as «class furl»
   else
       -- log "case 3 : " & theNewPath as string
       return theNewPath as string
   end if
end duplicateItemAtWithReplacing:toFolder:

#=====

on buildStamp()
   tell (current date) to return "_" & (((its year) * 10000 + (its month) * 100 + (its day)) as string) & "_" & text 2 thru -1 of ((1000000 + (its hours) * 10000 + (its minutes) * 100 + (its seconds)) as string)
end buildStamp

#=====

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 22 juin 2020 21:10:17

Last edited by Yvan Koenig (2020-06-22 02:08:10 pm)

Offline

 

#13 2020-06-22 03:04:03 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

I did some initial testing on this and it appears to be working! I'm using specifically Case #1.

Thanks for the help Yvan!

Offline

 

#14 2020-06-22 05:43:07 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

CAUTION, at least under 10.13.6, the way the system return errors is foolish.
If you try to copy an existing file (selected with Choose file) to a folder which doesn't exists, it issue a code error 4 and claims that it's the source item which is missing.
I found no better scheme than checking that the source and the target really exist before executing the duplicate command.


CAUTION 2. With case 1, if you try to duplicate an item which already exists in the target folder,  the system will issue error code 516 and the handler will politely return the descriptor of the item but nothing will be copied. It's useful only if you know that there is no existing replicate of the source.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 23 juin 2020 01:43:02

Last edited by Yvan Koenig (2020-06-22 05:56:26 pm)

Offline

 

#15 2020-06-24 03:09:17 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

I've updated my code and now the duped folder path gets passed to the newItem variable. So far so good.

The issue I'm running into now is when I start processing the files in that path. For example:

Applescript:

tell application "Finder"
   set fileName to name of newItem
end tell

This give's me the following error:

Finder got an error: Can’t get alias "path:to:newItem:".

Again this works if I do it to a local folder but not a folder on my server (since the 10.14 update).

The common denominator to both issues seems to be the that it's using the tell application "Finder" command. If you remember the command I had issues with was:

Applescript:

tell application "Finder"
   set newItem to duplicate thisItem to destinationFolder
end tell

Although interestingly the duplicate command worked just not the set command. Any ideas on a solve? I've having trouble deciphering how you circumvented the finder in the code you posted. Thanks.

Offline

 

#16 2020-06-24 05:51:12 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

foxbot wrote:

I've updated my code and now the duped folder path gets passed to the newItem variable. So far so good.

The issue I'm running into now is when I start processing the files in that path. For example:

Applescript:

tell application "Finder"
   set fileName to name of newItem
end tell

This give's me the following error:

Finder got an error: Can’t get alias "path:to:newItem:".

Again this works if I do it to a local folder but not a folder on my server (since the 10.14 update).

The common denominator to both issues seems to be the that it's using the tell application "Finder" command. If you remember the command I had issues with was:

Applescript:

tell application "Finder"
   set newItem to duplicate thisItem to destinationFolder
end tell

Although interestingly the duplicate command worked just not the set command. Any ideas on a solve? I've having trouble deciphering how you circumvented the finder in the code you posted. Thanks.



As far as I know, the Finder's dictionary doesn't state that the duplicate command is supposed to return a meaningful result.
It does on local devices, it did on servers but it no longer does with servers. You can't complain here. You were assuming that a non-documented feature was guaranteed to be available everytime. Just a wrong guess.

In my messages you have already all the infos required to do what you want.

According to a property defined at the very beginning of the scripts, my proposed handlers return a POSIXPath or a «class furl» object. The script below show how to get the name of such items.

Applescript:

use AppleScript version "2.5"
use scripting additions
use framework "Foundation"

set aFile to (choose file)
log aFile (*alias SSD 1000:Users:yvankoenig:Desktop:fool / copie.scpt*)
set aFurl to aFile as «class furl»
log aFurl (*file SSD 1000:Users:yvankoenig:Desktop:fool / copie.scpt*)
-- grab the name of a «class furl» object
set POSIXsource to current application's NSString's stringWithString:(POSIX path of aFurl)
set itsName to (POSIXsource's lastPathComponent()) as string
log itsName (*fool : copie.scpt*)
-- Instruction required if the Hfs name contain a slash
if itsName contains ":" then set itsName to my replace:itsName existingString:":" newString:"/"
log itsName (*fool / copie.scpt*)

set POSIXPath to POSIX path of aFile
log result
-- grab the name of a POSIX path object
set POSIXsource to current application's NSString's stringWithString:POSIXPath
set itsName to (POSIXsource's lastPathComponent()) as string
log itsName (*fool : copie.scpt*)
-- Instruction required if the Hfs name contain a slash
if itsName contains ":" then set itsName to my replace:itsName existingString:":" newString:"/"
log itsName (*fool / copie.scpt*)

on replace:sourceString existingString:d1 newString:d2
   set sourceString to current application's NSString's stringWithString:sourceString
   return (sourceString's stringByReplacingOccurrencesOfString:d1 withString:d2) as text
end replace:existingString:newString:

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 juin 2020 01:50:02

Offline

 

#17 2020-06-25 03:04:19 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

It seems that you drown in a glass of water.
Back to the very beginning.

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

is the same as

Applescript:

set myItem to "Server:Directory:To:MyFolder" as «class furl»
set destinationFolder to "Server:Directory:To:DestinationFolder:" as «class furl»

To duplicate, a correct syntax would be

Applescript:

tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
   set newItem to newItem as alias
end tell

because, if it returns something, duplicate return a Finder reference which must be converted into alias by the Finder itself.
The syntax above would be correct as long as the replicate is not already available.
To get rid of that, you may code

Applescript:

try
tell application "Finder"
   set newItem to duplicate myItem to destinationFolder
   set newItem to newItem as alias
end tell
end try

But if the replicate already exists, no newItem object would be returned.
You must use this alternate code:

Applescript:

tell application "Finder"
   set origName to name of item (myItem as string)
   set destHfs to destinationFolder as string
   if destHfs does not end with ":" then set destHfs to destHfs & ":"
   set newItem to destHfs & origName
   if not (exists item newItem) then duplicate myItem to destinationFolder
   set newItem to newItem as alias
end tell

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 juin 2020 11:03:10

Last edited by Yvan Koenig (2020-06-25 11:21:53 am)

Offline

 

#18 2020-06-25 11:14:31 am

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

I really appreciate all the time you've taken to respond. I will dig in and see if I can get everything up and running using what you've shown. Thanks!

Offline

 

#19 2020-06-25 02:34:17 pm

foxbot
Member
Registered: 2011-11-18
Posts: 16

Re: Can't Convert Server Finder Reference to Alias

Hi Yvan, sorry for the back and forth. I've been able to get most of my original script up and running but ran into a snag.

Since I can't rename files/folder on the server using the traditional method i.e.

Applescript:

set myItem to POSIX file "/Volumes/serverName/folder/" as alias

tell application "Finder"
   set the name of thisItem to "newName"
end tell

(throws an error: "Finder got an error: Can’t set alias \"serverName:folder:\" to \"newName\"." number -10006 from alias "serverName:folder:")

What is the method using NSFileManager to circumvent using Finder?

Offline

 

#20 2020-06-25 05:22:47 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

foxbot wrote:

Hi Yvan, sorry for the back and forth. I've been able to get most of my original script up and running but ran into a snag.

Since I can't rename files/folder on the server using the traditional method i.e.

Applescript:

set myItem to POSIX file "/Volumes/serverName/folder/" as alias

tell application "Finder"
   set the name of thisItem to "newName"
end tell

(throws an error: "Finder got an error: Can’t set alias \"serverName:folder:\" to \"newName\"." number -10006 from alias "serverName:folder:")

What is the method using NSFileManager to circumvent using Finder?




It's really boring to see that you are unable to use what is given to you.

I posted :

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
set destinationFolder to POSIX file "/Volumes/Server/Directory/To/DestinationFolder"

is the same as

Applescript:


set myItem to "Server:Directory:To:MyFolder" as «class furl»
set destinationFolder to "Server:Directory:To:DestinationFolder:" as «class furl»

To duplicate, a correct syntax would be



I never converted a POSIX File into an alias.

I posted:

Applescript:

set myItem to POSIX file "/Volumes/Server/Directory/To/MyFolder"
--…
tell application "Finder"
set origName to name of item (myItem as string)-- HERE IS THE CORRECT SYNTAX
set destHfs to destinationFolder as string
if destHfs does not end with ":" then set destHfs to destHfs & ":"
set newItem to destHfs & origName
if not (exists item newItem) then duplicate myItem to destinationFolder
set newItem to newItem as alias
end tell



I remember having see error -10006 (scripts dealing with Quicktime if I remember well) but I have no idea of what is wrong.
Maybe it's a problem of permissions and if it is, ASObjC will not help.
I already gave you in message #9 and message #16 every pieces of code useful to do what you want. As I am not a parrot, I will not repeat.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 juin 2020 01:22:08

Offline

 

#21 2020-06-25 05:44:54 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

If the instruction

Applescript:

set myItem to POSIX file "/Volumes/serverName/folder/" as alias

doesn't issue an error, it's that the named item really exists.
May you post the log history returned by:

Applescript:

set myItem to POSIX file "/Volumes/serverName/folder/" as alias

tell application "Finder"
   properties of myItem
   --set the name of thisItem to "newName"
end tell

It's supposed to return something like:
{class:folder, name:"Documents", index:25, displayed name:"Documents", name extension:"", extension hidden:false, container:folder "**********" of folder "Users" of startup disk of application "Finder", disk:startup disk of application "Finder", position:{204, 152}, desktop position:missing value, bounds:{172, 120, 236, 184}, kind:"Dossier", label index:0, locked:false, description:missing value, comment:"", size:7.807010854E+9, physical size:7.807090688E+9, creation date:date "mercredi 21 mai 2014 à 18:23:17", modification date:date "jeudi 25 juin 2020 à 19:12:23", icon:missing value, URL:"file:///Users/**********/Documents/", owner:"**********", group:"(inconnu)", owner privileges:read write, group privileges:none, everyones privileges:none, container window:container window of folder "Documents" of folder "**********" of folder "Users" of startup disk of application "Finder"}

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 26 juin 2020 01:44:49

Offline

 

#22 2020-06-27 04:06:58 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 4544

Re: Can't Convert Server Finder Reference to Alias

I searched in my archives.
Error -10006 is : errAEWriteDenied
which means that you aren't allowed to write to the target, (here change its name).
You must ask the administrator of the server why you are facing such feature.
Maybe it's a wrong setting but maybe there is a good reason to prevent you to do that.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 27 juin 2020 12:06:42

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)