Apple Script Virus

I am working on a minor virus made with aple script. It basically moves around the icons on your desktop constantly. With a little ResEdit hacking, I made it a background only application, so you’ll have to restart to quit. It doesn’t do too much harm, though. :wink:

Colin-
Well, I don’t really have a need to move around the icons on my desktop (hey, they’re disorganized enough already!). But I am curious about your ResEdit hack to convert an Applescript into a background only application; it seems like it could be quite useful for some applications. I’ve tried a couple times to convert an app to background only by changing the file type to “appe”, etc, but with no luck.

Think you could post the technique you used? I for one would certainly appreciate it…

Thanks!
Brad

I will appreciate as well me too
Roberto

Well, I’m glad you asked! I was using SuperResEdit at the time, and I’m not sure if it matters what version you use. To make an Application become a background-only application you:

  1. open up the app in ResEdit
  2. open up SIZE resorce, ID -1
  3. click on the “background only” check-box
  4. Let the mischief begin!

Son of a gun! At least with a bit of preliminary testing, it seems to work just fine. Had no idea it was so easy to get an app running in the background! I’m surpised I haven’t seen anything about this sort of thing at ResExellence or the other ResEdit sites. (Standard version of ResEdit works just fine for this btw.)

In looking at a list of my running processes, I notice that all the apps that were actually designed to be background only have a file type of “appe” rather than “APPL”. Not sure what the significance of this is. I suspect that something in the Finder or other apps may use this info to determine whether it is a foreground or background app. It’s easy enough to change the file type and bundle info to reflect the new file status; I’ll have to play with it some (or look into Apple’s tech notes) to figure out what impact it actually has.

Thanks for the information, Colin! I have a number of small apps (including some Applescripts) that run in the foreground even though it would make more sense for them to be background only applications. This could easily change the way I do things on my Mac, unless I run into problems that haven’t shown up yet. If I get anymore useful information about this, I’ll let you know!

Thanks again!
Brad

A gracious user at ResExcellence pointed me to the correct Apple Tech Note for understanding the problems that might arise from converting an app to background-only in the manner described here. Apparently there are several issues to pay attention to when performing this conversion: a background-only app has only 2K of stack space (as opposed to 24K for a regular app) and cannot put up dialogs or draw to the screen.

Whether it will work for a particular app is dependent on how the app is coded; a likely candidate for this conversion may cause a crash nonetheless by overflowing the stack etc.
Included a link to Apple’s notes on background-only applications below. I’d suggest that any interested in this trick read these first.

Brad

I havn’t noticed any change in “the virus” which I havn’t yet named. (I think I’ll call it The Uninvited Guest who rearranges the furniture.") Since it isn’t open all that much, I doubt it could crash, but I’ll find out soon enough.What kind of apps are you working on anyway? Just curious.

I’m still trying to determine if small Applescript applications can run safely as background-only. As long as the script does not try to put up dialogs or menus, it seems like they may be OK.

I’m not a programmer, but it sounds like the stack is used for variable storage for a normal application (not sure about Applescripts; they seem to use system memory a lot), and overflowing the 2K of stack memory can cause the app to crash. Several constructs (recursion, etc) can fill the stack very fast, and these should obviously be avoided if you want the app to run as a BOA. Looks like you do at least need to be careful about variable usage when doing this.

Of the other candidates that occurred to me, probably BeSpecific is the best example of a normal app that seems like it should’ve been a BOA. This is an app to use with KeyQuencer; it simply sits in the background and tells KeyQuencer to use a set of macros corresponding to the frontmost process.

But even a simple program like this is problematic. Most apps call InitWindows and InitMenus when they startup, which is apparently not allowed for background-only apps.

I’m still hopeful about Applescripts though. These are by no means “normal” apps, but rather a shell for a set of Applescript commands. The issue of Applescripts was the first thing to come up after I posted my question at ResExcellence; I’ll let you know if anyone has an answer!

Brad

BTW, I like the name, but “The Uninvited Guest who rearranges the furniture” is more than 31 characters, so you won’t be able to use it as a file name…bummer.

Colin-
OK, think I’ve found something definite to tell you!

Evidence I’ve got would indicate that an Applescript makes the same calls on starting up that any simple app would make. Which is to say it DOES make some calls that are NOT allowed for background-only apps.

Some people seem to feel that this is not a big argument against turning them into BOAs (people have been breaking the rules from Inside Macintosh for years); a well-written script will probably never crash your machine if it TRIES to behave like a good BOA, even though it does do some things it shouldn’t.

On the other hand, other people seem to take Apple’s warnings seriously. Leonard Rosenthal (author of OSA Menu and RegEx Commands) has written a shell that allows you to run scripts as supposedly well-behaved backround-only applications (or FBA - facelss Background app). You can download it from link below.

I tried it and It works great! That FBA really works wonders. The script still needs some refining, though. It doesn’t move desktop icons around anymore. It just displays some weird stuff. I have now called it The Phantom Virus.

Wow, this has been a great thread to read through. Thanks go out to you all. We just posted a note from Chris Espinoza (Applecript Team) about memory usage in Applescript. Its a pretty well written article and sheds some light on a few of the things mentioned in thoughout this thread. Click on the “Examples” button in the banner above/below to read it. Thanks for the very ineresting info, very cool stuff.

Greg

OK, I know this is a little late but hey, I only found the site yesterday & have been reading back…

There is a small “appe” (extension application - usually FBA that are stored in the extenstion folder to launch at startup…) called ScriptHider. You can use it to lauch AppleScripts that can’t be quit (unless you quit ScriptHider). Get it from the URL below…

HI Steve

There are a couple of ways to do this. My first thought is a “helper” osax called AutoType Osax. It should do what your needing. It allows you to hook dialogs, by a simple tell statement. You can tell it to “click” on the default button, or any other button (but usually whatever is the default button). There are a couple of other osax that allow you to do this. I think Akua Sweets does too. You can find the link for AutoType in our Scripting Additions section below.

Hope this helps - let me know

Ray~

Do you mean the startup screen? When you save your script as an application, check the box called “Never show startup screen”.

NG

I’m new to applescript and found it bizarre and frustrating that a Yes/No dialog comes up before the script can be run. My script does invoke a necessary dialog (for printing) so I can’t background it. Is there any other way to get rid of that silly dialog box?

Just an FYI. I saw a post in this thread that someone was suprised they never saw the "Saving a script as a BOA with ResEdit at resexcellence. It actually has been there for quite a while, including a script to move around all of the icons on the desktop. You can find both at:

[url=http://www.ResExcellence.com/applescripts_99.shtml]http://www.ResExcellence.com/applescripts_99.shtml[/url].