Oni Central Forum

A forum for the Oni community

You are not logged in.

#1 01/02/08 12:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Mac programming

A thread for Mac and Oni related programming discussions.

Offline

#2 01/02/08 12:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

You're right, we were totally off-topic in that thread.  Anyway, my response was:

Right, the exact issue is finding the folder where Oni.app resides.  Could you try these in AppleScript?  I'm not at my Mac.  "tell current application to return my name" (then try "path" instead of "name"), and "path to frontmost application".  Hopefully neither require 10.5, because the docs I'm reading are updated for Tiger.  If you can get one of those to return the proper path to the AEI (you could test them by making a dialog that shows the result), then I can get the path to work within the Unix script side of the AEI; I've already had to write code that translates AppleScript's path format to the POSIX format Unix uses.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#3 01/02/08 14:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

"tell current application to return my name" produces:
"Script Editor"

"tell current application to return my path" produces:
AppleScript error "Can't get path"

"path to frontmost application" produces
alias "Macintosh HD:Applications:AppleScript:Script Editor.app:"

Last edited by EdT (01/02/08 14:01)

Offline

#4 01/02/08 14:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Sorry, wasn't clear, you have to save the script as an application and run that.  But it already looks like "path to frontmost application" is teh win.  I will post the code tomorrow for converting to a Unix-style path, unless you figure it out before then.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#5 01/02/08 14:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

How do you get xCode to display the texts from the shell script?
For example the echo commands in a script such as:
echo "Looks like you've never installed the Edition before."

I made an app with one button "BigZeal" linked it to the AppleScript. The code for the script is:

on clicked theObject
    if name of theObject = "bigzeal" then
        do shell script "cd ~/Applications/Oni/edition/install/; ./big_deal.sh"
    end if
end clicked

This sort of works, except the applications crashes, but it does run the script.

Last edited by EdT (01/02/08 19:01)

Offline

#6 01/02/08 23:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

I found this bit of code:

tell application "Finder" to get POSIX path of ((container of (path to me)) as text)
do shell script quoted form of result & "edition/install/big_zeal.sh"

It will execute the script.  However, the shell script still thinks its in the root directory, so it will not execute properly.
At least I'm getting closer...

I'm beginning to think I should just stick to Platypus and make 3 different wrappers for the scripts.

Offline

#7 01/03/08 09:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Well, I can't tell why it would crash without seeing the rest of the code, but it looks like you're taking an unnecessarily complicated approach to scripting the app.  Usually you just do something like:

if (errNum is equal to -128) then -- User cancelled.
        display dialog "No file chosen. Use the default file?"
        if button returned of result is equal to "OK" then
            display dialog "The script will continue " & ¬
                "using the default file \"" & fileName & "\"."
        end if
    else
        -- If any other error, do nothing.
    end if

rather than setting up objects and getting click events from them.

I personally think AppleScript is the way to go, but I don't know Platypus at all.  But I know this whole thing can be done very simply in AS.  Perhaps I should have just written the app myself last night, but I thought I would just fill in what you needed to know and let you handle it since you were already started on it.  See my next post for further response.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#8 01/03/08 09:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

I found this bit of code:

tell application "Finder" to get POSIX path of ((container of (path to me)) as text)
do shell script quoted form of result & "edition/install/big_zeal.sh"

The problem with the POSIX path routine is that it doesn't escape any characters.  It's useless except for substituting slashes for colons.  So, if any part of the path had a space in it, it would fail to convey the right path to Unix.  I wrote this code a while ago:

on make_path_UNIX_safe(path_name, safe_path_name)
    set target_string to " "
    set limit to count of characters in path_name
    set offset_list to {}
    
    repeat with x from 1 to limit
        if character x in path_name is target_string then
            set offset_list to offset_list & " " & x
            set safe_path_name to safe_path_name & "\\"
        end if
        set safe_path_name to safe_path_name & character x in path_name
    end repeat
    return safe_path_name
end make_path_UNIX_safe

It only escapes the space character, which in hindsight should be a problem, but never has been.  Technically you may need to escape other characters like single-quote, and some need to be converted to special codes.  I could write that part pretty easily, but as long as one doesn't use anything other than [space] in their file paths leading to Oni, there won't be a problem.  There could even be a warning to that effect in the AEI dialog box.  It's a rare instance that it would be the case.

Just to be clear, you call my above function by saying

set cmd_string to "" as string
set safe_path to "" as string
set safe_path to my make_path_UNIX_safe(path_name, safe_path)
set cmd_string to "cd " & (safe_path as string) & "; bash [insert path to installer script here]"
do shell script cmd_string
display dialog result as string

where path_name is already set to the POSIX path of the original path string.  That code snippet also shows you how to see the result of the script, but it doesn't allow for feedback, where you have to press Enter to continue.  Frankly, I would do away with that part of the script, as implementing it is difficult and unnecessary; on the Mac, we don't ask for needless confirmation of things we obviously meant to do.  It's enough for the AEI dialog box to say "You should back up your installation of Oni before proceeding."  I mean, the script always says the same thing, asking for the Enter key for confirmation, right?  It's not necessary to have a second dialog just for confirmation.  The user knows what an Installer is when he/she click on the script app.

It will execute the script.  However, the shell script still thinks its in the root directory, so it will not execute properly.

Again, see my code above to see how I combine strings to get cmd_string, the command that is passed to bash.  Try modeling your code as closely to what I have posted as possible.  There's two or three things wrong with the code you posted that are lengthy in explaining but fast in fixing if you learn from my example above.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#9 01/03/08 09:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritscen: I was using xCode to build the app and the code was from the applescript.
If you have time, can you try to build the app also. I'm struggling to learn xCode, applescript, myself.
I appreciate your assistance.

EDIT: I guess we posted at the same time.  I will give your code a try.  But I'm out of time now.

Last edited by EdT (01/03/08 09:01)

Offline

#10 01/03/08 10:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

I see.  You can just use Script Editor, forget Xcode when all you're doing is writing AppleScript code.  Then you just save the script as a standalone app.  Much simpler than starting a project in Xcode.  I was confused because when you ran the code before to find a path, it was giving you Script Editor.app's path, so I assumed all your work was being done there.

I will write something tonight if I have time.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#11 01/03/08 16:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

I wanted to use xCode to create an application so the user can select from the various installs big_deal, big_zeal, new_deal with just a click on the button. 

Also, I wanted a display for feedback, doing the first install can take a relatively long time 20 minutes+   Without any feedback, progress bar... the output the terminal gives, the user may think the program is not working or it crashed and so forth.

If you can write an Applescript that can run the shell scripts of Edition with some feedback, that will be awesome.

Offline

#12 01/04/08 09:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Attached is AEI v1.0a.  Open it in Script Editor, and choose "Save as...", then save it as an application bundle in the edition folder inside the Oni folder.  Find that script, which should be called Anniversary Edition Installer.app, and double-click it.  You can save testing time by just hitting the Update Install button.  The Full Install button should definitely work if the Update Install button does.

Known bugs/limitations:
- Does not handle characters in path to script that need escaping except [space]
- Will not run unless echo and read lines in edition/new_deal.sh, big_deal.sh, and big_zeal.sh are removed, so that input from user is not required to execute shell script
- Cannot give feedback on progress or eventual success
- AppleScript dialogs only support three buttons, so that meant that I could only have a Quit button and two scripts to choose from.  I decided that the Full Install button would simply use big_zeal.sh, which is just big_deal.sh with more log files, right?

I've asked geyser to stop in here and talk with us about helping to bridge the gap between what the installer can do and what his scripts have to do.  Geyser, the main thing right now is removing the lines that ask the user to press a key to continue.  As I said before, I think that, at least for the Mac edition, what with having a proper installer app now (or soon), the need for confirmation by the bash scripts is unnecessary.  Do you agree?

Getting progress is a little tricker, but I agree we should strive to incorporate that.  It's not hard to get the textual result of the install scripts that run, and look at what level has been done last to get the total progress, but the thing is, that result only comes through when the script is done running, all at once.  I have to test that, but I'm pretty sure that's the case.

I once developed a workaround for this sort of problem, but it's a kludge.  It uses AppleScript Events to actually open Terminal, enter the command and run it, then hide the Terminal while it runs, but gets the window's contents, check the contents for changes, and analyzes the changes to look for keywords that indicate success.  This could also be used for progress indicators.

Here's another option: incorporating geyser's overarching scripts into the Installer.  If the Installer is able to directly run the step__.sh scripts, it will have at least that much to go by as a progress indicator, but with no more than four steps running (four, right?), that's still not a lot of progress.  Another option, which is more work for geyser, is breaking down the scripts to work on each level at a time within each step.  As each step-level script finishes, the Installer can then give the user progress feedback.  "Done with level 1 SNDD files... Done with level 2 SNDD files...", then moving on to the other kinds of files, level by level.

I will brainstorm today about other options that don't require more work from geyser that will cause the Mac and Windows scripts to diverge so much.  But what do you think of the options thus far?  Also, will all Mac users reading this try out the script?  Follow the instructions at the top of this post.  Even if it doesn't run, it won't eat your hard drive or anything.

Last edited by Iritscen (01/04/08 12:01)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#13 01/04/08 16:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Thanks, I'll give it try tonight.  Too much work right now...

Offline

#14 01/04/08 18:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

I got the error message:
sh: line 1: cd /Applications/Oni/edition/AEI.app: No such file or directory big_zeal.sg: big_zeal.sh: No such file or directory

Same thing with new_deal.sh

Last edited by EdT (01/04/08 18:01)

Offline

#15 01/04/08 23:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

woot! I got it to work!  Its a xCode application, just put it in the Oni folder and you can choose between the 3 scripts, big_deal, big_zeal and new_deal.

Iritscen: Thanks to your script I was able to get it done.

Next is to figure out how to get the shell script output to appear in a window during the process.

Last edited by EdT (01/05/08 18:01)

Offline

#16 01/05/08 12:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Unfortunately, your app opens and closes without doing anything.  Can you compile it as a Universal app?

The error you got for mine is odd.  Can you comment out the two lines that say "do shell script", and uncomment the display dialog lines adjacent to those, and tell me what pressing one of the buttons gives you?

P.S.: Make sure ZeroLink is turned off in Xcode.

Last edited by Iritscen (01/05/08 12:01)


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#17 01/05/08 14:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

You're right, I tested my app on my Macbook and it crashed.  I was using xCode on my ppc Mac with OSX 10.4.11, npw I have to try xCode that came on my Macbook.

I get the message:
cd /Users/edt/Applications/Oni/edition/AEInstall.app; cd..; bash big_zeal.sh

and the Macbook give me the error message when running the script:
sh: line 0: cd /Users/edt/Applications/Oni/edition/AEInstall.app: Not a directory
bash: bash big_zeal.sh: No such file or directory

Last edited by EdT (01/05/08 18:01)

Offline

#18 01/05/08 18:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Here's a recomplied version of AEI, I downloaded the latest xCode.
It now runs on IntelMacs.

Last edited by EdT (01/05/08 18:01)

Offline

#19 01/05/08 20:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

According to the Tech notes on Apple's website: http://developer.apple.com/technotes/tn2002/tn2065.html

Q: My script will produce output over a long time. How do I read the results as they come in?

A: Again, the short answer is that you don’t — do shell script will not return until the command is done. In Unix terms, it cannot be used to create a pipe. What you can do, however, is to put the command into the background (see the next question), send its output to a file, and then read the file as it fills up.

That's beyond my level of experience... oh well...

Offline

#20 01/06/08 17:01

geyser
Member
From: beyond the veil
Registered: 01/14/07
Website

Re: Mac programming

"I wanted to use xCode to create an application so the user can select from the various installs big_deal, big_zeal, new_deal with just a click on the button."
Ed, why don't you set up Platypus wrappers for the 3 of them (the ones located in [edition], not in [edition/install])? Wouldn't that be convenient enough? smile
That way, updates of the Edition would modify the ones in [edition/install], which would still be called up by the Platypus executables in [edition] as before.

Note that I might modify the layout of the directories a bit for the actual Anniversary: I'll try to make it more modular and SVN-friendly.


Behold the power of that which is yet unborn! For the swirling images that flow forth from the Chrysalis are only a shadow of the sleeper's true power.

Offline

#21 01/06/08 19:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

why don't you set up Platypus wrappers for the 3 of them

I didn't realize that writing the app would be so hard.  I made one that works, but it provides no feedback to the user.
But, its a learning experience...

Offline

#22 01/07/08 11:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

It's strange that my script would do that... what's happening is simply that it's putting the ~ before the address.  Your copy of Oni is at /Applications/Oni, right?  You'll notice that it's prepending your user folder to your application folder's location.  This should be an easy fix, but it's odd that it works for me and not you.  You are using the bash shell, right (type chsh to show current shell)?  I can also implement the progress reporting, once that is fixed.  Give me a little more time and it should be working smoothly.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#23 01/07/08 15:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Iritiscen:  Not sure why I have that problem. I'm using Tiger on my PPC. I has an idea to try, why not have AEI open up the terminal then the user can see the progress of the install or update.  That may be the easiest way.

Offline

#24 01/07/08 16:01

Iritscen
Moderator
From: NC, USA
Registered: 10/22/07

Re: Mac programming

Yeah, I will need to do that in order to get the progress.  But I can also hide the Terminal after opening it and read the window while it's hidden.  It's a handy trick I developed a while ago.  The code's written and ready to be plugged into this project.  I will have to get to the bottom of the path problem, though.


Check out the Anniversary Edition Seven at ae.oni2.net!

Offline

#25 01/07/08 16:01

EdT
Moderator
From: Los Angeles, CA
Registered: 01/13/07
Website

Re: Mac programming

Cool:  I'll also work on the path problem.

EDIT: This script works for me.

Last edited by EdT (01/07/08 19:01)

Offline

Board footer

Powered by FluxBB