Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Renaming a file or a folder

38 views
Skip to first unread message

André Tremblay

unread,
Jul 12, 2018, 9:56:13 PM7/12/18
to SuperCard Discussion
Hello, 

I am trying to emulate Rinaldi's FullRename XCFN which had the form of:

  FullRename <file/folder pathname>,<new name>[,"DontResolveAlias"]

it allowed to rename a file or a folder by providing an HFS path name and and a chunk text as a new name. 

Actually I don't really need the “Don't resolve alias feature”. 

In case of a file the original extension should be preserved. 

I can't find a way to do it directly with SuperCard. 

I've wrote two AppleScript scripts, one native and one using a shell that work just fine with the AppleScript Editor. 

But when I call then with SC with :

get appleScript(file, path[, handler[, param(s)]])


I am getting with both of them the Error -1728 specifying that “It is impossible to obtain «class pALL»” of the target file. 


Would someone have a suggestion?


Regards



codegreen

unread,
Jul 12, 2018, 10:40:59 PM7/12/18
to SuperCard Discussion
On Thursday, July 12, 2018 at 9:56:13 PM UTC-4, André Tremblay wrote:

Would someone have a suggestion?


Um, post the script that's throwing the error?

-Mark 

André Tremblay

unread,
Jul 12, 2018, 11:13:43 PM7/12/18
to SuperCard Discussion
Hello Mark, 

Here is the call from SC : 

function Renommer CheminHFS,NvoNom  

  put DossierSuperApp()& "AppleScript" & ":" into ChDossAScript 

  put ChDossAScript &"Renommer.scpt" into ASScript

  return appleScript(file,ASScript,"Renommer",CheminHFS,NvoNom)

end Renommer


Thank you for help.


André Tremblay

PhotoGraphex

codegreen

unread,
Jul 12, 2018, 11:20:48 PM7/12/18
to SuperCard Discussion
LOL! Yeah, but that error is being generated by the AppleScript...

codegreen

unread,
Jul 12, 2018, 11:26:56 PM7/12/18
to SuperCard Discussion
In the meantime, does this give you any ideas?

on mouseUp

  answer file "Select a file to rename:"

  if it = "" then exit script

  put it into theFile

  ask file "Rename file as:"

  if it = "" then exit script

  put it into newName

  if theFile newName then put shell(merge("mv -f `[[hfsToPosix(theFile)]]` `[[hfsToPosix(newName)]]`"))

end mouseUp


Note that if the source and destination folder are different this will actually MOVE the file (which you could preclude with a bit of scripting, if that's a problem...).


-Mark

André Tremblay

unread,
Jul 13, 2018, 3:00:02 PM7/13/18
to SuperCard Discussion

In the meantime, does this give you any ideas?

Perfect! It is up and running! My reflex was to call the shell from AppleScript! I forgot I can do it from SC!

Nevertheless , I wonder what might be causing the call to AppleScript form SC to return:

Error -1728 specifying that “It is impossible to obtain «class pALL»” of the target file

Any ideas? 

codegreen

unread,
Jul 13, 2018, 3:19:05 PM7/13/18
to superca...@googlegroups.com
I''m definitely not an experienced enough AppleScripter to know off the top of my head what sort of action commonly throws this error, but the fact that the description contains guillemets is a dead giveaway that it's generated by AppleScript.

Since SC's appleScript function is new in 4.8 I don't have much experience with it yet either, but so far it seems most errors when a script runs successfully in the Script Editor but not when called that way are due to type coercion failures (where the input or output of a script is some AppleScript structured data type that the scripter tries to act on or return directly, without coercing it from/to a string first as necessary). It seems like the Script Editor has code to automagically handle some such implicit coercions for you, but the appleScript function doesn't. If the result you see in the Script Editor is multi-colored, this generally indicates that it's actually a complex type (not a simple string), and so just trying to return it will likely generate an error.

But that's all just blowing smoke without actually seeing your AppleScript...

-Mark

André Tremblay

unread,
Jul 13, 2018, 6:07:16 PM7/13/18
to SuperCard Discussion
Thanks a bunch Mark for the lead, your explanation make sense, l'll give a more thoughtful look to it!

For the time being, calling a Shell from SC works very very well!

Regards

André Tremblay
PhotoGraphex 
Reply all
Reply to author
Forward
0 new messages