HyperCard Converter app batch conversion

31 views
Skip to first unread message

Ramanoir

unread,
Mar 6, 2022, 10:02:47 PM3/6/22
to SuperCard Discussion
I wonder if there is an existing script or if it is possible to script a batch conversion with the HyperCard Converter app?

I have several hundreds of HC stacks to convert and it would be handy!

Regards

André Tremblay

MARK LUCAS

unread,
Mar 7, 2022, 12:42:10 AM3/7/22
to via SuperCard Discussion
The HyperCard Converter is a thin SuperCard standalone wrapper around an XFcn called ImportStack, so it should be trivial to script. Just collect your list of HFS stack paths and pass each in turn to something like this (massaging the output file path as you see fit):

request merge("importStack(`[[theStak]]`, `[[theStak]].sc45`, false)") from program "HyperCard Converter"


HTH,
-Mark

MARK LUCAS

unread,
Mar 7, 2022, 1:26:54 AM3/7/22
to via SuperCard Discussion
In case that wasn't self-explanatory:

on mouseUp
  answer folder "Select a folder of stacks to import:"
  if it = "" then exit script
  put it into theFolder
  put dir(theFolder, false, false, cr, "TYPE", "STAK") into theStacks
  repeat for each line aStack of theStacks
    request merge("importStack(`[[theFolder & aStack]]`, `[[theFolder & aStack]].sc45`, false)") from program "HyperCard Converter"
  end repeat
end mouseUp

-Mark

Photographex

unread,
Mar 7, 2022, 10:04:50 PM3/7/22
to 'MARK LUCAS' via SuperCard Discussion
Hello Mark


Le 07-mars-2022 à 00:42:04, 'MARK LUCAS' via SuperCard Discussion <superca...@googlegroups.com> a écrit :

The HyperCard Converter is a thin SuperCard standalone wrapper around an XFcn called ImportStack, so it should be trivial to script. Just collect your list of HFS stack paths and pass each in turn to something like this (massaging the output file path as you see fit):

request merge("importStack(`[[theStak]]`, `[[theStak]].sc45`, false)") from program "HyperCard Converter"

Being from the generation that just need to type “Magic” in a message box to get a miracle, I knew there was a function!

Is possible of legal to get it to install in the main project? To be sure it stays handy!

Thanks for your “ready to serve” script: 

on mouseUp
  answer folder "Select a folder of stacks to import:"
  if it = "" then exit script
  put it into theFolder
  put dir(theFolder, false, false, cr, "TYPE", "STAK") into theStacks
  repeat for each line aStack of theStacks
    request merge("importStack(`[[theFolder & aStack]]`, `[[theFolder & aStack]].sc45`, false)") from program "HyperCard Converter"
  end repeat
end mouseUp

What is the use of the third boolean parameter?

I just added a destination folder and the following script went though the folder after a few hours on a MacPro with an internal SSD. 

For SuperCarders' information, it took this form: 

on ConvertHCStacks -- Mark Lucas 20220307 --> To convert batch folder of HC legacy stacks
   --∆ The "HyperCard Converter.app" should be opened
   local SourceFolder,ConvertFolder,aStack,theStacks,ScriptAE,ResultAE,AppAE="eppc://localhost/HyperCard Converter"
   answer folder "Select a folder of stacks to import:"
   if it = "" then exit script
   put it into SourceFolder
   answer folder "Select a folder to export converted stacks :"
   if it = "" then exit script
   put it into ConvertFolder
   set cursor to busy -- TRACE -- ==========
   put dir(SourceFolder, false, false, cr, "TYPE", "STAK") into theStacks
   --E?  ask list theStacks -- "Chose some projects"
   set the allowInterrupts to true
   repeat for each line aStack of theStacks
      put merge("importStack(`[[SourceFolder & aStack]]`,`[[ConvertFolder & aStack]].sc45`, false)") into ScriptAE
      request ScriptAE from program AppAE --EX "HyperCard Converter"
      put aStack && the result 
      -- put ScriptAE via program "<MyHD>:Applications:SuperCard 4.81:HyperCard Conversion:HyperCard Converter.app" into ResultAE
      -- put the result into ResultAE
      if interrupt() then exit repeat
   end repeat
   return theStacks 
end ConvertHCStacks

Maybe because of the Mojave MacOS version I used for testing, the AppleEvent form: 

request merge("importStack(`[[theFolder & aStack]]`, `[[theFolder & aStack]].sc45`, false)") from program "HyperCard Converter"

This identification of the program is returning this result: "Got error number -1743 from AppleEvent ->

Most likely for a reason security, to overcome this issue, I changed the identification of the program to this URL address:

AppAE="eppc://localhost/HyperCard Converter"

Which do work fine after the customary connection dialog. 

I also tried the form "via program", but I wasn't able to avoid an error. It would be also an interesting option with an auto launch of the "HyperCard Converter" application. 

I would have I like to be able to get file dialog selection that would permit partial selection of documents, but it doesn't seem to be possible. As this is a script with rare occasional use, it's fine as it is!

Seeing the list of local variables, it remind me a wish to be able to increase the width of the column of the variables in ScriptTracer to be ajustable to more than 10 characters wide!

My best regards

André Tremblay


MARK LUCAS

unread,
Mar 7, 2022, 10:39:06 PM3/7/22
to via SuperCard Discussion
On Mar 7, 2022, at 10:04 PM, Photographex <photogr...@gmail.com> wrote:

Is possible of legal to get it to install in the main project? To be sure it stays handy!

Sorry, the standalone is password-protected (so you can't export star resources).

What is the use of the third boolean parameter?

It enables debug mode, which just basically writes messages to the console saying what card it's chewing on to provide clues in case of a crash.

Maybe because of the Mojave MacOS version I used for testing, the AppleEvent form: 

request merge("importStack(`[[theFolder & aStack]]`, `[[theFolder & aStack]].sc45`, false)") from program "HyperCard Converter"

This identification of the program is returning this result: "Got error number -1743 from AppleEvent ->

Most likely for a reason security, to overcome this issue, I changed the identification of the program to this URL address:

AppAE="eppc://localhost/HyperCard Converter"

Which do work fine after the customary connection dialog. 

That's a permission error of course, which FWIW I don't see here (but then GateKeeper is less finicky about locally compiled binaries, so that could be the reason). As you deduced using the eppc addressing form lets you sidestep that, but I suspect it's probably also quite a bit slower. Unfortunately AppleEvent permissions are a total train wreck in Mojave (as you probably already know) so there's likely no easy fix.

-Mark


MARK LUCAS

unread,
Mar 8, 2022, 2:08:00 PM3/8/22
to via SuperCard Discussion
On Mar 7, 2022, at 10:04 PM, Photographex <photogr...@gmail.com> wrote:

I would have I like to be able to get file dialog selection that would permit partial selection of documents, but it doesn't seem to be possible.

Is this what you meant?

on mouseUp
  local thePrompt = "Choose some HyperCard stacks to import:", ¬
    theScript = merge("set AppleScript's text item delimiters to return[[cr]]" & ¬
    "try[[cr]]return (choose file with prompt `[[thePrompt]]`" && ¬
    "of type {`STAK`} with multiple selections allowed) as string[[cr]]" && ¬
    "on error[[cr]]return ``[[cr]]end try"), theStacks = appleScript(theScript)
  repeat for each line aStack of theStacks
    request merge("importStack(`[[aStack]]`, `[[aStack]].sc45`, false)") from program "HyperCard Converter"
  end repeat
end mouseUp

-Mark

MARK LUCAS

unread,
Mar 8, 2022, 2:08:28 PM3/8/22
to via SuperCard Discussion
On Mar 7, 2022, at 10:04 PM, Photographex <photogr...@gmail.com> wrote:

Seeing the list of local variables, it remind me a wish to be able to increase the width of the column of the variables in ScriptTracer to be ajustable to more than 10 characters wide!

BTW the Tracer variables watcher's display should auto-size to accommodate long names. Are you seeing something different?

-Mark

MARK LUCAS

unread,
Mar 8, 2022, 6:26:23 PM3/8/22
to via SuperCard Discussion
On Mar 7, 2022, at 10:04 PM, Photographex <photogr...@gmail.com> wrote:

I also tried the form "via program", but I wasn't able to avoid an error. It would be also an interesting option with an auto launch of the "HyperCard Converter" application. 

You should be able to use via to access the XFcn so long as you do it from the SuperCard Player (or a distributable standalone), so you don't get a password dialog when opening the host project. For example:

on mouseUp
  if the environment "SuperCard Player" then
    alert stop "This script must be run from the Player!" explain "It opens a project you don't have the password to..."
  else
    local cnvrtr = converterPath()
    lock messages
    open inv wd 1 of proj cnvrtr
    local thePrompt = "Choose some HyperCard stacks to import:", ¬
      theScript = merge("set AppleScript's text item delimiters to return[[cr]]" & ¬
      "try[[cr]]return (choose file with prompt `[[thePrompt]]`" && ¬
      "of type {`STAK`} with multiple selections allowed) as string[[cr]]" && ¬
      "on error[[cr]]return ``[[cr]]end try"), theStacks = appleScript(theScript)
    repeat for each line aStack of theStacks
      get importStack(aStack, aStack & ".sc45", false) via proj cnvrtr
    end repeat
    close proj cnvrtr
  end if
end mouseUp

function converterPath
  local vers = the version, tail = last word of vers
  repeat while tail empty and not isNumber(tail)
    delete last char of tail
  end repeat
  put tail into last word of vers
  return posixToHFS(merge("/Applications/[[trim(vers)]]/HyperCard Conversion/HyperCard Converter.app/Contents/Resources/main.sc45"))
end converterPath

If I were gonna make a standalone out of this I'd also copy the main.sc45 project from the HyperCard Converter to my standalone's :Contents:Resources folder (and rename it something like ImportStack.sc45) just so I always knew where it was, then call the XFcn from there:

    local cnvrtr = the application & "Contents:Resources:ImportStack.sc45"

-Mark

Photographex

unread,
Mar 8, 2022, 8:58:11 PM3/8/22
to 'MARK LUCAS' via SuperCard Discussion

Le 08-mars-2022 à 14:07:51, 'MARK LUCAS' via SuperCard Discussion <superca...@googlegroups.com> a écrit :

Is this what you meant?

You are reading my mind! That's exactly the equivalent I was looking for!

As laziness or the lack of time is the mother of all inventions, I opted instead to install the script on a test standalone on the server computer where the files are local. After launching "HyperCard Converter.app" and a few hours of precesses, it crashed (SuperCard 4.82.crash.txt) after 222 HC legacy stacks conversions, fortunately the most important conversions were done. 

Thanks a bunch for your all “cooked up” script ready to take out: 

local thePrompt = "Choose some HyperCard stacks to import:", ¬
      theScript = merge("set AppleScript's text item delimiters to return[[cr]]" & ¬
      "try[[cr]]return (choose file with prompt `[[thePrompt]]`" && ¬
      "of type {`STAK`} with multiple selections allowed) as string[[cr]]" && ¬
      "on error[[cr]]return ``[[cr]]end try"), theStacks = appleScript(theScript)

It fits the need perfectly and it will be much useful for a lot of purposes, for the benefit of the SuperCarders, here is a working script with this improvement using the eppc URL address:

on ConvertHCStacks -- Mark Lucas 20220307 --> To convert a user's selection of HC legacy stacks
   --∆ The "HyperCard Converter.app" should be opened
   local SourceFolder,ConvertFolder,aStack,theStacks,ScriptAE,ResultAE,AppAE="eppc://localhost/HyperCard Converter"
   local thePrompt = "Choose some HyperCard stacks to import:", ¬
      theScript = merge("set AppleScript's text item delimiters to return[[cr]]" & ¬
      "try[[cr]]return (choose file with prompt `[[thePrompt]]`" && ¬
      "of type {`STAK`} with multiple selections allowed) as string[[cr]]" && ¬
      "on error[[cr]]return ``[[cr]]end try"), theStacks = appleScript(theScript) -- 20220308
   answer folder "Select a folder to export converted stacks :"
   if it = "" then exit script
   put it into ConvertFolder
   set cursor to busy 
   set the allowInterrupts to true -- TRACE -- ==========
   repeat for each line HFSPathStack of theStacks
      put pathTools("fileFromPath",HFSPathStack) into aStack
      put merge("importStack(`[[HFSPathStack]]`,`[[ConvertFolder & aStack]].sc45`, false)") into ScriptAE
      request ScriptAE from program AppAE
      put aStack && the result --> ∆ Looking for a better progress window
      if interrupt() then exit repeat
   end repeat
   return theStacks 
end ConvertHCStacks

My best regards,

André Tremblay

Photographex

unread,
Mar 8, 2022, 9:18:12 PM3/8/22
to 'MARK LUCAS' via SuperCard Discussion

Le 08-mars-2022 à 14:08:21, 'MARK LUCAS' via SuperCard Discussion <superca...@googlegroups.com> a écrit :

BTW the Tracer variables watcher's display should auto-size to accommodate long names. Are you seeing something different?

Well! Yes and no! 

In the ScriptTracer the minimum width of the first column is 10 characters, when the variable have more than 10 chars it does “push” right the second column, breaking the visual alignment. 

It may be just fine for most users, but in my case when I routinely deal with scripts having several dozens of variables, it would greatly helpful as a visual helper if the width of the first column of the ScriptTracer could be user's settable, with a property for instance. 

Also, having the option to detach the 'Variables' window from the main ScriptTracer window would be in many occasions very helpful!

Thanks for considering, 

André Tremblay

MARK LUCAS

unread,
Mar 8, 2022, 9:50:48 PM3/8/22
to via SuperCard Discussion

On Mar 8, 2022, at 8:58 PM, Photographex <sdcsain...@gmail.com> wrote:

After launching "HyperCard Converter.app" and a few hours of precesses, it crashed (SuperCard 4.82.crash.txt) after 222 HC legacy stacks conversions

Hmmm, bad star ID, not sure what's goin' on there.

Luckily it died in your standalone someplace and not in the Converter code (under this distributed model the import function lives in a different process, but if you used via things would all be running - likely much more efficiently - in a single copy of the interpreter). 

So yeah it still sucks that it crashed, but at least we know it wasn't the converter's fault…

-Mark

Photographex

unread,
Mar 8, 2022, 10:18:49 PM3/8/22
to superca...@googlegroups.com
Le 08-mars-2022 à 18:26:14, 'MARK LUCAS' via SuperCard Discussion <superca...@googlegroups.com> a écrit :

You should be able to use via to access the XFcn so long as you do it from the SuperCard Player (or a distributable standalone), so you don't get a password dialog when opening the host project.

I see, as I was testing with the SuperCard application, I was wondering how to call the 'ImportStack' function. 

I like your second options, after opening the content of the "HyperCard Converter.app", I was able to locate in the 'Ressources' folder the "main.sc45" project, make a copy and rename it "ImportStack.sc45" and move it to a location for the standalone application making. 

With the "Standalone Maker.app" under the 'Ressource' tab, I am able to import the "ImportStack.sc45" project. 

But, when I try to build the standalone, I am getting the error "The source project is write protected", with the editable option or not!

If there isn't a copyright issue with the ImportStack function, wouldn't it be simpler to just copy the xcfn to the actual user's project? 

By the way, the AppleEvent eppc call seems to work just fine, if there is an overhead, it's minimal in this context!

Regarding the previous crash while converting, should I mention that there were THREE SuperCard standalone applications running simultaneously on different tasks!!!

Maybe, should I have checked "the realMemorySize" or "the virtualmemorysize" properties for the application memory footprint and stop it at safe 3 Mb size! This do generally and efficiently prevent crashes for the multi hours processes. 

Now with the latest version of the script with the AppleScript user's "multiple selections allowed" dialog, it will be easy to send the remaining stacks for conversion.

Thanks for your support,

André Tremblay

MARK LUCAS

unread,
Mar 8, 2022, 11:30:08 PM3/8/22
to via SuperCard Discussion

On Mar 8, 2022, at 10:18 PM, Photographex <sdcsain...@gmail.com> wrote:

But, when I try to build the standalone, I am getting the error "The source project is write protected", with the editable option or not!

FWIW I just tried this here and I'm not seeing any problems. I dragged a copy of the main.sc45 project from The Converter out onto my Desktop, renamed it ImportStack.sc45, then dragged it into the Resources tab of the make file for my standalone and built it without incident. The posted script ran as expected. In any event you can always drag ImportStack.sc45 (or whatever you've elected to call it) into the standalone after you've built it if that shuts SaM up.

If there isn't a copyright issue with the ImportStack function, wouldn't it be simpler to just copy the xcfn to the actual user's project? 

It would be if you had the password, which I'm not at liberty to divulge.

By the way, the AppleEvent eppc call seems to work just fine, if there is an overhead, it's minimal in this context!

I'm sure the overhead is at least a couple of orders of magnitude greater than via, but in this context (i.e., since the dispatched task is so heavily I/O bound) that may not matter much...

-Mark

MARK LUCAS

unread,
Mar 8, 2022, 11:32:41 PM3/8/22
to via SuperCard Discussion
And make sure you haven't got the standalone's root project open already in another app when you try to build, IIRC SaM wants write access…

-Mark

André Tremblay

unread,
Mar 9, 2022, 9:10:44 PM3/9/22
to 'MARK LUCAS' via SuperCard Discussion

Le 08-mars-2022 à 23:32:33, 'MARK LUCAS' via SuperCard Discussion <superca...@googlegroups.com> a écrit :

And make sure you haven't got the standalone's root project open already in another app when you try to build, IIRC SaM wants write access…

Hey, hey! Your long experience is showing and you have the nose of a bloodhound!

That's exactly that!

Doing too many things at the same time, when I did the standalone making with the "Standalone Maker.app", I forgot to close the "HyperCard Converter.app" and the source projet that was busy on another task!

After closing both of them, the standalone making with the import of the "ImportStack.sc45" with the 'Resources' tab, the application building went like a hot knife in a lump of butter!

I'll will use your script proposal with "the environment" checking and post the script after testing!

While being in this subject, I bring another question that could be another thread, but here it is!

Is there an xfcn that may replace the UNIX RegEX built-in in the MacOS system? 

I am using the "unixTask("", "/bin/bash", "-c", regex)" for several tasks, but MacOS Tiger 10.4.6 have an older version of RegEX, that create an error with I am testing my project on this system. I know, because you already explain it, that it is possible to upgrade RegEX on this system, but a substitution would assure a better compatibility for deployment. 

Many thanks!

André 

MARK LUCAS

unread,
Mar 9, 2022, 11:28:24 PM3/9/22
to via SuperCard Discussion
Could you post some examples of the expressions you're going to use?
Reply all
Reply to author
Forward
0 new messages