Sunday, November 23, 2014

#1 2009-03-13 06:08:52 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Mac Finder native copy dialog

I meet one requirement
1) copy files into a a folder,
2) Require same behavior as Mac drag file action, such as pop up "Copy" dialog asking confirm if there is a same name file in the target folder..

Applescript has copy command of "Finder",

Applescript:


tell application "Finder"
try
copy file "file.." to folder "folder.."
end try
end tell

This code can only meet my 1) requirement, but not the 2) requirement. So could anybody tell the solution for me?


One mans trash is another mans treasure

Filed under: Finder, copy

Offline

 

#2 2009-03-13 06:16:09 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10672
Website

Re: Mac Finder native copy dialog

Hi,

the proper Finder command to move files is move, not copy
and duplicate to copy files.
The requested confirm behavior can be forced with replacing ask

Applescript:


tell application "Finder"
   move file "file.." to folder "folder.." replacing ask
end tell

Note: don't use try blocks while testing scripts. You will never get any helpful error message, if something goes wrong


regards

Stefan

Filed under: Finder

Offline

 

#3 2009-03-15 08:16:44 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Mac Finder native copy dialog

Thanks for your help.

But follow your request, I meet below error message in the terminal,

execution error: Finder got an error: An item with the same name already exists in the destination. (-15267)

My code is:

Applescript:

tell application "Finder"
activate
move file " *:*:*:a.txt" to folder "*:*:*:a:" replacing ask
end tell

Is there anything wrong in my script?

Last edited by minigabriel (2009-03-15 08:21:56 pm)


One mans trash is another mans treasure

Filed under: Finder

Offline

 

#4 2009-03-15 08:20:20 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: Mac Finder native copy dialog

And there no confirm dialog pop up.
Actually, I hope Finder can pop up "confirm" dialog in this case.


One mans trash is another mans treasure

Offline

 

#5 2009-03-16 03:21:57 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10672
Website

Re: Mac Finder native copy dialog

just  omit "replacing ask". Paradoxically then the Finder asks


regards

Stefan

Offline

 

#6 2010-12-21 06:34:22 am

hypernikomen
Member
Registered: 2010-12-06
Posts: 1

Re: Mac Finder native copy dialog

I can't get the Finder to ask.
"replacing yes" or "with replacing" replaces the file without asking.
"replacing no" or "without replacing" leads to an error message about the file already existing.
"replacing ask" leads to the same error message.
Omitting the replacing stuff also leads to that error message.

"Replacing" of the command "move" is boolean, according to the AppleScript Dictionary. Boolean means it can be either true or false. Could it be that the "ask" value is not even supported in this case?
In cases where "ask" is supported, the dictionary says "ask/no/yes" instead of "boolean", like in the command "close" (in Pages or AppleScript Editor, for example) where "saving" can be "ask/no/yes".

Offline

 

#7 2012-05-03 06:19:48 pm

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 14
Website

Re: Mac Finder native copy dialog

StefanK wrote:

just  omit "replacing ask". Paradoxically then the Finder asks

Not here. I.e. not when I run my script from within Script Editor or as a standalone .app, built on 10.6.8.
HOWEVER: If I run the same script in Script Debugger, then I get the Finder to ask about replacing the existing item.

I've posted the same question today on SO, here: http://stackoverflow.com/questions/10430506
It includes an example.

This is still a mystery.

Stefan, if you get the dialog, would you please describe your testing environment and show the script you're using? Unless you're testing in SD - then it's no wonder it works (well, it's still unclear _why_ it works in SD).

Last edited by tempel (2012-05-03 06:21:50 pm)

Offline

 

#8 2012-05-03 06:29:42 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3796

Re: Mac Finder native copy dialog

hypernikomen wrote:

"Replacing" of the command "move" is boolean, according to the AppleScript Dictionary. Boolean means it can be either true or false. Could it be that the "ask" value is not even supported in this case?

That's the case. If you want a dialog, you need to use "without replacing", trap for an error, put up your own dialog, and proceed accordingly.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#9 2012-05-03 06:42:37 pm

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 14
Website

Re: Mac Finder native copy dialog

Shane Stanley wrote:

That's the case. If you want a dialog, you need to use "without replacing", trap for an error, put up your own dialog, and proceed accordingly.

Shane, please read the posting I made on StackOverflow.

What you're suggesting is a work-around, but not the only option, as one can see if one tries this in Script Debugger, which achieves to get the dialog from the Finder, just as the original poster asked for. And StefanK's reponse suggests as well that there's some way to get the Finder to show the dialog just as if one had initiated the copy/move directly in the Finder.

Last edited by tempel (2012-05-03 06:44:12 pm)

Offline

 

#10 2012-05-03 07:11:10 pm

Shane Stanley
Member
From: Australia
Registered: 2002-12-07
Posts: 3796

Re: Mac Finder native copy dialog

I'm not sure why SD 4.5 is doing it that way, but I'd classify it as a bug. I understand it results in the behaviour preferred, but IMO exploiting bugs usually backfires at some stage. The dictionary is explicit: "replacing" is a boolean parameter.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

#11 2012-05-04 02:34:03 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10672
Website

Re: Mac Finder native copy dialog

tempel wrote:

StefanK wrote:

just  omit "replacing ask". Paradoxically then the Finder asks

Not here. I.e. not when I run my script from within Script Editor or as a standalone .app, built on 10.6.8.
HOWEVER: If I run the same script in Script Debugger, then I get the Finder to ask about replacing the existing item.

I've posted the same question today on SO, here: http://stackoverflow.com/questions/10430506
It includes an example.

This is still a mystery.

Stefan, if you get the dialog, would you please describe your testing environment and show the script you're using? Unless you're testing in SD - then it's no wonder it works (well, it's still unclear _why_ it works in SD).

I'm not sure where the replace ask form comes from, maybe it was an option in a former AppleScript version.

Regardless of the real existing problem your code on stackoverflow contains the wrong command copy instead of move.

Indeed I'm using ScriptDebugger, so everything behaves exactly as you described.

As a solution/workaround you could catch the error and display your own warning dialog.
Then the behavior in ScriptDebugger / Script Editor is (almost) the same

Applescript:


set sourceFile to "disk:path:to:file.ext"
tell application "Finder"
   try
       move file sourceFile to desktop
   on error errorMessage number errorNumber
       if errorNumber = -15267 then
           display dialog "An item named \"file.ext\" alreeady exists in this location. Do you want to replace it with the one you're moving" buttons {"Stop", "Replace"} cancel button "Stop" with icon caution
           move file sourceFile to desktop replacing yes
       else
           display dialog errorMessage & " (" & errorNumber & ")"
       end if
   end try
end tell


regards

Stefan

Offline

 

#12 2012-05-04 02:41:10 am

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 14
Website

Re: Mac Finder native copy dialog

Stefan,

You confirm that you see the same effect in SD, so when you wrote a while back that you get the Finder's dialog, you were probably also testing this in SD, right? However, if you managed to get the Finder's dialog outside of running the script in SD, that would be the interesting part this thread would like to explore more.

The question remains: SD does something that leads to the effect to have the Finder handle the conflict, and I want to find out how to archieve that. (Note: I am actually using this script, or AppleEvents, in my own larger app, so this script is just an example, not the solution). Working around by showing my own dialog is just not the same, and so I keep pressing to find out how SD does it.

Last edited by tempel (2012-05-04 02:44:02 am)

Offline

 

#13 2012-05-04 02:54:34 am

StefanK
Member
From: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 10672
Website

Re: Mac Finder native copy dialog

tempel wrote:

You confirm that you see the same effect in SD, so when you wrote a while back that you get the Finder's dialog, you were probably also testing this in SD, right? However, if you managed to get the Finder's dialog outside of running the script in SD, that would be the interesting part this thread would like to explore more.

I'm working only with SD, for my own stand alone projects I'm always using the shell or even Objective-C for file management.

tempel wrote:

The question remains: SD does something that leads to the effect to have the Finder handle the conflict, and I want to find out how to archieve that. (Note: I am actually using this script, or AppleEvents, in my own larger app, so this script is just an example, not the solution). Working around by showing my own dialog is just not the same, and so I keep pressing to find out how SD does it.

I guess only Late Night Software can answer the question


regards

Stefan

Offline

 

#14 2012-05-10 03:38:07 am

tempel
Member
From: Germany
Registered: 2010-11-19
Posts: 14
Website

Re: Mac Finder native copy dialog

I've received a reply from Mark Alldritt at Latenight Software.

He knew of this "issue" and investigated it a while ago. He could not figure out the details of this behavior, though.

The only lead is that SD is using its own OSA Component.

Now, where do I find a skeleton OSA Component to try this myself? wink

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.027 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)