This page is a wiki. Please login or create an account to begin editing.


6 posts / 0 new
Last post
IWishTodayWasStill2004's picture
Joined: 2012 May 25
Troubles writing automated scripts

Relative to "Macintosh OS 7.5.5 (emulation disk image)", I was thinking of making a new "Starter Disk" with some automated scripts which would help people who are new to the Macintosh Garden (such as a script to convert a "read-only compressed" NDIF disk image to just a "read-only" NDIF disk image (also making the resulting disk image self-mounting if possible) and stuff the resulting disk image). However, iI need some help with doing these automated tasks:


1. if exists folder - Sometimes the scripts extract in paths such as "Starter Disk:Archive" being extracted to "Starter Disk:Archive :", and the scripts would only know that the archive was extracted to "Starter Disk:Archive :", but I don't know how to find the parent directory, so then I tried if exists folder "Starter Disk:Archive :", but that always shows a "false" condition even if the folder exists, and I also tried if exists folder "Starter Disk:Archive ", but that also always show a "false" condition. Will anyone help me with this, or at least with finding the parent directory of a file or folder so I can use the normal syntax of if exists folder (eg. if exists folder "Archive " of "Starter Disk:")
2. move (folder) to trash - Again, if the extraction of an archive in a script was unsuccessful, the script should check if the folder the script meant to extract the archive to (eg. "Starter Disk:Archive ") exists, and if it does exist, then it would move that folder to Trash, but when I try something like move "Starter Disk:Archive :" to trash or move "Starter Disk:Archive " to trash, I get a "Finder got an error: Expected a reference" Execution Error message. What is that "reference" anyway and how do I convert a path to that "reference" Finder wants?
EDIT: I've got these problems fixed by myself

3. As for any script to open the DropStuff application, the script should check the version of the "Starter Disk:System Folder:Extensions:StuffIt Engine" file; if the version is 3.5.x, then the script should tell Finder "open file \"Starter Disk:DropStuff 3.5.2 Folder:DropStuff\"", and if the version is 5.5, then the script should tell Finder "open file \"Starter Disk:Aladdin DropStuff 5.5:DropStuff\"", but how do I check the version of a file in AppleScript? EDIT: Answered by MikeTomTom (#6)

and I've uploaded the first revision of the "Macintosh Garden's Starter Disk" here. This discussion should be closed and there should be a new forum topic discussing the new Starter Disk.

Edit: Replaced 'xxx 7' by 'Mac OS 7' - IIGS User

Comments

MikeTomTom's picture
Offline
Joined: 2009 Dec 7

making the resulting disk image self-mounting if possible

Keep in mind that creating .smi images requires Mac OS 8.1 or later to build them.

1. if exists folder

Refer to "startup disk", e.g:

tell application "Finder"
activate
if exists folder "Archive" of startup disk then
select folder "Archive" of startup disk
delete selection
empty Trash
else
display dialog "The folder Archive does not exist, or has been deleted." ¬
with icon 1 buttons {"Cool"} default button 1
end if
end tell

The above also answers question 2 partially. I saw you'd answered your own question as I was typing this, so decided to leave it here anyway.
Note the symbol "¬" above, it denotes a single line of AppleScript broken over successive lines for readability (use the "Option & Return" keys in AppleScript to employ, if needed).

I think question 3 will be the difficult one. Because when downloading stuffed files off the web the creator code and file type is usually missing from ".sit" files. At best, the Finder will interpret the codes as belonging to the most recent Stuffit application installed and assign creator and file types to the file as such (and therefore can get it wrong every time). At worst it will assign every generic file as TEXT. So one usually has to manually drag a generic icon onto the appropriate app to expand it OK. Stuffit has to work it out for itself from the data content as to whether or not it is able to deal with the file. I'm fairly sure thats the case, anyway.

IWishTodayWasStill2004's picture
Joined: 2012 May 25

In #3, I don't mean checking what StuffIt version a .sit file was created using, but I mean to check the version (stored in the "VERS" resource) of the StuffIt Engine installed and open the appropriate version of DropStuff based on the version. DropStuff 3.5 has many bugs that cause it to only work with version 3.5 of the StuffIt Engine, and DropStuff 5.5 won't work without version 5.0 or later of the StuffIt Engine, so only one of the two versions of DropStuff that would be installed on the "Starter Disk" would work depending on the version of the StuffIt Engine, so that's why I want the script to check the version of the StuffIt Engine. Does anyone at least know who to get information from a resource in a file's resource fork (for this script, the VERS 1 resource)?

MikeTomTom's picture
Offline
Joined: 2009 Dec 7

Does anyone at least know who to get information from a resource in a file's resource fork

-----------------------
tell application "Finder"
activate
copy "::System Folder:Extensions:StuffIt Engine™" to y
select alias y
open information windows of alias y
copy version of alias y as text to x
if "5.5" is in x then
if (word 1 of x) < "5.5" then
display dialog "Its pretty old" buttons {"OK"} default button 1 with icon 1
else
display dialog "Its version 5.5" buttons {"Cool"} default button 1 with icon 1
end if
end if
end tell
-----------------------

Refer to "alias" of items
I don't know if "information windows" works in Mac OS's, pre OS 9 but it might be OK.

You should be able to get enough from the above to help you somewhat.

[Edit]: Have tested the above on a number of Mac OS's and it works fine with Mac OS 8.1 to 9.2.2

However, it is broken in Mac OS 7.1 to 7.6.1 as AppleScript in those versions are unable to parse the line "copy version of alias y as text to x". I didn't have Mac OS 8.0 to try it in but from 8.1 & later its OK as is.

Edit: Replaced 'xxx 7' by 'Mac OS 7' - IIGS User

IWishTodayWasStill2004's picture
Joined: 2012 May 25

However, it is broken in Mac OS 7.1 to 7.6.1 as AppleScript in those versions are unable to parse the line "copy version of alias y as text to x".

Then your method wouldn't be suitable for a script on the Starter Disk I'm thinking of because that Starter Disk would still only have Mac OS 7.5.5 installed.

Edit: Replaced 'xxx 7' by 'Mac OS 7' - IIGS User

MikeTomTom's picture
Offline
Joined: 2009 Dec 7

And in the meantime I figured out what does make the above work with all versions of Mac OS from 7.1 through 9.2.2

-----------------------
tell application "Finder"
activate
set x to info for file "::System Folder:Extensions:StuffIt Engine™"
x's short version
set y to the result
if y = "5.5" then
display dialog "Its version 5.5" buttons {"Cool"} default button 1 with icon 1
else
display dialog "Its version " & y & "" buttons {"OK"} default button 1 with icon 1
end if
end tell
-----------------------