HC with AppleScript -> Rev with Applescript
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
HC with AppleScript -> Rev with Applescript
I have a number of HC stack that I need to get out of Classic to run on new hardware as old hardware it getting harder to find.
In my stacks, I have loaded Applescripts into the stack script as a bunch of functions that except parameters. I then link those stacks (start using) to all my others so that I do not need to put the Applescript code in everything.
The Applescript code, talks to Quark Express, Sql Grinder, Distiller, url scripting and a couple of other apps.
I have an older version of Rev (DreamCard 2.5.#) that I want to use as a first step to get me to the newer hardware.
How do I replicate the functionality of storing Applescript functions in a stack and calling them, passing in parameters?
Do I create a function and build the Applescript command as a text string, and then execute it within the function? What kind of preformance hit it there compiling the code to run each time as I will be calling it 100's of times to produce the products.
I know some functionality Rev can replace, like the stuff done by url scripting, and possibly Sql Grinder to get to the database.
Is there a resource somewhere that has some examples of this sort of thing?
Thanks
Lloyd
In my stacks, I have loaded Applescripts into the stack script as a bunch of functions that except parameters. I then link those stacks (start using) to all my others so that I do not need to put the Applescript code in everything.
The Applescript code, talks to Quark Express, Sql Grinder, Distiller, url scripting and a couple of other apps.
I have an older version of Rev (DreamCard 2.5.#) that I want to use as a first step to get me to the newer hardware.
How do I replicate the functionality of storing Applescript functions in a stack and calling them, passing in parameters?
Do I create a function and build the Applescript command as a text string, and then execute it within the function? What kind of preformance hit it there compiling the code to run each time as I will be calling it 100's of times to produce the products.
I know some functionality Rev can replace, like the stuff done by url scripting, and possibly Sql Grinder to get to the database.
Is there a resource somewhere that has some examples of this sort of thing?
Thanks
Lloyd
Lloyd,
welcome to the forum.
It can be done, but a little different from the way Hypercard did this. In Hypercard you had the option to run native applescript. In Rev you do not.
What you got is the 'do something as applescript' and the result gives you back what you queried.
That sounds limited but once you get the idea it lets you do pretty much anything you did in Hypercard.
One thing is that you have to quote your applescript in Rev like:
That is how many people do it as they use only small scripts. But I find it complicated to write and read.
I ususally do it this way:
I put the following into a field, native applescriptthen in Rev I say 'do field "xyz" as applescript
This is a lot easier to maintain than the quoted form.
If I want to pass variables to the applescript I declare them in Rev like this (it is an example where I want to extract 4 annotations of a quicktime movie and use these annotations in Rev)
in field "appleScript2" is this as simple text
theAnnos is a comma delimited list of my 4 annotations
well I hope this makes any sense to you.
One thing. I script the applescript in Script Debugger from Late night software. It lets you debug your applescript in ways that the Skripteditor does not. It sounds like you are doing serious applescripting, like production scale, I you have not used Script Debugger have a look at it. Anyways you want to do your debugging of applescript outside of Rev.
To sum it up:
Of course you can do one stack that you start to 'use' with all your applescript stuff. It is just different from the way Hypercard used to do it, which was more 'native'.
regards
Bernd
welcome to the forum.
andThe Applescript code, talks to Quark Express, Sql Grinder, Distiller, url scripting and a couple of other apps.
That sounds like some serious rescripting.as I will be calling it 100's of times to produce the products
It can be done, but a little different from the way Hypercard did this. In Hypercard you had the option to run native applescript. In Rev you do not.
What you got is the 'do something as applescript' and the result gives you back what you queried.
That sounds limited but once you get the idea it lets you do pretty much anything you did in Hypercard.
One thing is that you have to quote your applescript in Rev like:
Code: Select all
put "tell application " & quote & "Finder" & quote & cr & \
"activate" & cr & \
"open folder " & quote & "MyHD:MyFolder:MySubfolder" & quote & cr & \
"end tell" into tScript
I ususally do it this way:
I put the following into a field, native applescript
Code: Select all
tell application "Finder"
activate
open folder
open folder "MyHD:MyFolder:MySubfolder"
end tell
This is a lot easier to maintain than the quoted form.
If I want to pass variables to the applescript I declare them in Rev like this (it is an example where I want to extract 4 annotations of a quicktime movie and use these annotations in Rev)
Code: Select all
.........
-- convert the Rev style path (/my/path/to/file.txt) to mac style
-- Macintosh HD:my:path:to:file.txt with revMacFromUnixPath
put revMacFromUnixPath (localFilmPath) into localPathforAppleScript
-- set up a variable for the applescript containing the filepath
put "Set theFile to " & quote & localPathforAppleScript & quote & return into varForApplescriptAnnotations
-- append the whole field with the applescript
put field "appleScript2" after varForApplescriptAnnotations
-- execute the applescript
do varForApplescriptAnnotations as applescript
-- the result contains the annotations from the movies in a format that I set up in the applescript, then I take that apart and have my annotations
put the result into fromAppleScriptAnnotations
.................
Code: Select all
tell application "QuickTime Player"
open file theFile
set condition2 to ""
set Macher to ""
set cellType to ""
set condition1 to ""
set theAnnos to ""
tell movie 1
try
set condition2 to full text of annotation "Comment"
end try
try
set Macher to full text of annotation "Copyright"
end try
try
set cellType to full text of annotation "Author"
end try
try
set condition1 to full text of annotation "Producer"
end try
end tell
set theAnnos to theAnnos & Macher & ","
set theAnnos to theAnnos & cellType & ","
set theAnnos to theAnnos & condition1 & ","
set theAnnos to theAnnos & condition2
if (count of documents) = 1 then quit
end tell
-- here the annotations are passed back to Rev
return theAnnos
well I hope this makes any sense to you.
One thing. I script the applescript in Script Debugger from Late night software. It lets you debug your applescript in ways that the Skripteditor does not. It sounds like you are doing serious applescripting, like production scale, I you have not used Script Debugger have a look at it. Anyways you want to do your debugging of applescript outside of Rev.
To sum it up:
Of course you can do one stack that you start to 'use' with all your applescript stuff. It is just different from the way Hypercard used to do it, which was more 'native'.
regards
Bernd
Thanks for the info.
I guess I will need to rework the scripts as the AppleScript also has logging and error catching in it. I guess I may need to catch those in Rev and do the logging from Rev.
We use HC to drive our daily newspaper production, and it has run great for the past 10 years linking Quark and databases together. Now that hardware is getting scarce I need to get away from classic.
I'll need to give this a serious look to see if I can make this work.
Thanks again
Lloyd
I guess I will need to rework the scripts as the AppleScript also has logging and error catching in it. I guess I may need to catch those in Rev and do the logging from Rev.
We use HC to drive our daily newspaper production, and it has run great for the past 10 years linking Quark and databases together. Now that hardware is getting scarce I need to get away from classic.
I'll need to give this a serious look to see if I can make this work.
Thanks again
Lloyd
Hi, Bernd,
I need a little advice from you. I have grasp the idea how apple script works with RunRev. I have a little problem with into what field in the stack I should put the apple script code. I know how to import apple script in RealBasic but while I am transitioning to RunRev I am experiencing this problem. Both you and the manual mention that apple script code should go into "A FIELD" in the stack, but what exactly is this field and how to find it?
Thank you.
vkozme
I need a little advice from you. I have grasp the idea how apple script works with RunRev. I have a little problem with into what field in the stack I should put the apple script code. I know how to import apple script in RealBasic but while I am transitioning to RunRev I am experiencing this problem. Both you and the manual mention that apple script code should go into "A FIELD" in the stack, but what exactly is this field and how to find it?
Thank you.
vkozme
Hi vkozme,
welcome to the forum.
In Revolution if you want to make a text field you drag it from the tools palette onto a stack. Than you might want to name that field in the inspector (look for the first item in the object menu).
That is it. Now you can put text into this field by either typing or pasting it into the field, just as you would paste an applescript into that field. If you want you can hide that field because it's only purpose is to hold the applescript.
Just remember that when you send an applescript and you expect a resonse/result from the applescript the applescrpt has to – return – the value which you retrieve byfor further processing.
You don't necessarily have to put an applescript into a field, as shown in the messages above you can build them in a script, which I find tedious and error prone because of all the quotes involved.
Again if I want to use applescript variables for e.g. file pathes or to initialise variables I build them in the script in a variable, then append the main body of the applescript from the field and do that as applescript.
It really works very well if you have working applescripts that you will want to write/debug in the "Scripteditor" or in "Script Debugger" which is what I use.
If you have questions feel free to ask
regards
Bernd
welcome to the forum.
In Revolution if you want to make a text field you drag it from the tools palette onto a stack. Than you might want to name that field in the inspector (look for the first item in the object menu).
That is it. Now you can put text into this field by either typing or pasting it into the field, just as you would paste an applescript into that field. If you want you can hide that field because it's only purpose is to hold the applescript.
Just remember that when you send an applescript and you expect a resonse/result from the applescript the applescrpt has to – return – the value which you retrieve by
Code: Select all
put the result into myVariable
You don't necessarily have to put an applescript into a field, as shown in the messages above you can build them in a script, which I find tedious and error prone because of all the quotes involved.
Again if I want to use applescript variables for e.g. file pathes or to initialise variables I build them in the script in a variable, then append the main body of the applescript from the field and do that as applescript.
It really works very well if you have working applescripts that you will want to write/debug in the "Scripteditor" or in "Script Debugger" which is what I use.
If you have questions feel free to ask
regards
Bernd
Hi, Brend,
Thank you very much for your reply. It worked as you said. I like "Script Debugger." I have been using it since 2004 - very cool. I just started playing with Runtime Revolution yesterday, although I was keeping my eye on it during last 2-3 years. How would you compare it to RealBasic?
Can you recommend some source of information to learn the syntax of RunRev. How to initialize variables? How to convert integers into string? Is there an equivalent of RB's timer (some code executed once or repeatedly based on the predefined time lap).
Thank you again for your response - you made my life a lot easier. I very appreciate your help.
vkozme
Thank you very much for your reply. It worked as you said. I like "Script Debugger." I have been using it since 2004 - very cool. I just started playing with Runtime Revolution yesterday, although I was keeping my eye on it during last 2-3 years. How would you compare it to RealBasic?
Can you recommend some source of information to learn the syntax of RunRev. How to initialize variables? How to convert integers into string? Is there an equivalent of RB's timer (some code executed once or repeatedly based on the predefined time lap).
Thank you again for your response - you made my life a lot easier. I very appreciate your help.
vkozme
Hi vkozme,
applescript should work from a stack just as well as from a standalone.
I never used Realbasic but there was a discussion on this forum a while ago where RealBasic and Revolution was discussed:
http://forums.runrev.com/phpBB2/viewtop ... =realbasic
Very helpful for beginners with Revolution is the Revolution Resource Center. BTW what version of Revolution are you using. If you are using any of the current version you can access the Resource Center from the Help menu.
It walks you through the creation of stacks and teaches you the syntax along the line. You can download for many of the examples a PDF and often there is a video that shows you how. On top you can download most of the example stacks to fiddle around with. Then there is the User Guide that you also access via the Help menu.
>How to initialize variables
Revolution initializes the variable for you so if you say
then Revolution creates a variable 'myVariable' and assigns it the value of 5.
>How to convert integers into string
Revolution converts integers into strings on the fly, you dont have to do that.
In the above example you could than say
than your text field "myField" would contain the string, you guessed it:
5 cats were kicked by Dixie today
>Is there an equivalent of RB's timer
in Revolution there is a send in time command, it sends a command, well, in a certain time to the stack/card or handler that issued this command.
This is very handy since Revolution takes care of sending this command and you dont have to wait or do anything for this to happen. On top it is a very efficient command since it frees Revolution to do other things instead of waiting for your handler to finish.
Typically you use it instead of a repeat loop when the loop would wait for things to happen. Of course you can resend this command every time you receive it in your issuing handler.
An example would be in a button:For this to work you make just a new stack and a button with this script. And a field that you name "myPosition". As long as the mouse is pressed the field will indicate the position of the mouse. Polling is perfect for this send in time construct because if you do it in a repeat loop and poll for a longer time Revolution might get upset because that would be a blocking handler versus a non-blocking when you use 'send in time'
All of the above is true to the best of my knowledge except that Dixie of course did not kick the cat, never.
regards
Bernd
applescript should work from a stack just as well as from a standalone.
I never used Realbasic but there was a discussion on this forum a while ago where RealBasic and Revolution was discussed:
http://forums.runrev.com/phpBB2/viewtop ... =realbasic
Very helpful for beginners with Revolution is the Revolution Resource Center. BTW what version of Revolution are you using. If you are using any of the current version you can access the Resource Center from the Help menu.
It walks you through the creation of stacks and teaches you the syntax along the line. You can download for many of the examples a PDF and often there is a video that shows you how. On top you can download most of the example stacks to fiddle around with. Then there is the User Guide that you also access via the Help menu.
>How to initialize variables
Revolution initializes the variable for you so if you say
Code: Select all
put 5 into myVariable
>How to convert integers into string
Revolution converts integers into strings on the fly, you dont have to do that.
In the above example you could than say
Code: Select all
put myVariable & " cats were kicked by Dixie today" into field "myField"
5 cats were kicked by Dixie today
>Is there an equivalent of RB's timer
in Revolution there is a send in time command, it sends a command, well, in a certain time to the stack/card or handler that issued this command.
This is very handy since Revolution takes care of sending this command and you dont have to wait or do anything for this to happen. On top it is a very efficient command since it frees Revolution to do other things instead of waiting for your handler to finish.
Typically you use it instead of a repeat loop when the loop would wait for things to happen. Of course you can resend this command every time you receive it in your issuing handler.
An example would be in a button:
Code: Select all
on mouseDown
send whereIsTheMouse to me in 10 milliseconds
end mouseDown
on whereIsTheMouse
if the mouse is not up then
put the mouseLoc into field "myPosition"
send whereIsTheMouse to me in 10 milliseconds
end if
end whereIsTheMouse
All of the above is true to the best of my knowledge except that Dixie of course did not kick the cat, never.
regards
Bernd