Today, for some odd reason, one of the four scripts in my project has lost its syntax coloring. It still works. I can edit it and add to it, but it appears as though all of the code were commented out. It is a pretty long script, but somewhere in between versions it lost its color. Does anyone know of a good fix other than reverting to a previous version and losing lots of time?
Thanks in advance.
I had the same enigmatic problem before and was wondering if it was a bug in Xcode. Perhaps it is. This and a few other aberrations that I tended to ignore in the past so long as I can get a quick fix.
The only temporary solution (acceptable, I think, in the absence of the original method) is to open the AppleScript file in “source code” format.
Open your file (they will look like ordinary text file), wait for a while then choose the menu item “Open As” in the File menu, and select “As Source Code”. Your file will appear with formatting. You can change the default format (color and font) in Xcode’s Preferences.
I am still looking for the old method however. There are a lot of things to like with that…like automatic formatting of lines when you save the script, etc. That does not happen in the new format.
If you happen to discover a better fix, I would appreciate if you can share your workaround in this forum.
Thank.s I hope the above helps.
If I make a typo in a script in Xcode, and save instead of ‘compiling’ then saving, the text goes black (unformatted), without giving me an error. Is this what you are experiencing?
I think my problem is the same as deanshavit’s so I am posting for both of us. He can, of course, post his reply if his problem is not the same.
My problem just happened–no warning --when I opened my project file. All my AppleScript codes just came out black. The differentiating colors for variables, reserved words, etc that I used to see just went pfft!. The whole thing looked like plain text file.
Did I give you the picture?
Thanks for any tip that could solve this problem. As of now, I am still on the “Save As Source Code” mode because that’s the closest thing I can have with colors and a little bit more.
It seems that the issue is related to length. My main script is very long, with many if/then statements and after a few hours of finagling, I finally cut out some of the recent changes, saved, and the coloration was back. I added some more back, and it went black again. I don’t know if it’s a bug or not, but I decided to place a lot of the longer if/then statements in a library script and call them as handlers and that seems to be working out well. I don’t think it’s a typo as Querty suggested.
I think you hit the nail right on the head.
My problem, just like yours, happened when my script became too big. With small scripts, it’s not a problem although occasionally, I do notice that when I save (not compile) even short scripts, sometimes the formatting does not take place. I have to do a “Select All” to induce the formatting to happen. This is perhaps a bug in AppleScript.
Thanks for the tip.
I updated to XCode 2.1 over the weekend and the syntax coloration issue has disappeared.
Just an FYI.
Thanks for the info deanshavit.
It’s a humungous download though - v2.1 is a whopping 750MB to download. Without a DSL or cable modem, I’d have to wait nearly forever.
The syntax coloring problem will happen in short scripts as well as long ones. It is a compilation problem, not a file size one. I think that larger scripts are more prone to the problem for a couple reasons. One, because once the compiler runs into an error it becomes more likely that some bit of code further down in the script will conflict in such a way as to make Xcode lose track of what kind of file it is. Essentially, it can’t tell that it’s a script and colors it like a plain text file. Second, from a user point of view, it’s easier to make a mistake and then not be able to find it when you’ve got hundreds (or thousands ;)) of lines of code. I’ve had projects with a hundred lines do this as often as I’ve had my projects with 2000 lines do it. Just out of curiousity, how long is a “long” script in your opinion?
As Qwerty Denzel mentions, it’s almost always caused by saving without compiling first, for me too. What happens is that you make a change to the script that won’t compile, and then save your work. Because Xcode doesn’t compile code when saving… only when building… it has no idea that you just saved something invalid. Then, when you go to open the file, Xcode tries to determine what kind of file it is, and then apply the appropriate type of formatting for that file type. But, because it won’t compile, Xcode freaks out and just spits it out as plain text until you can convince it that the file is valid applescript. Because Xcode also refreshes the file contents/view at times other than compiling and opening, the loss of syntax coloring can also happen under other conditions, too… like while you’re working on the file, not just when you open it. Usually I just backtrack through the most recent changes I’ve made and undo them until I can compile ok. It oftentimes is a missing bit of syntax or an incorrect reference (like ‘tell application “X”…’) and for some reason “application X” just doesn’t compute.
Thanks once again for an enlightening explanation.
I forgot what I actually did before the problem surfaced. Yes, perhaps I did make a save before compilation which may have introduced an uncompilable error.
Now, if only AppleScript has an excellent debugger that would tell me where or what the problem is, that would make hunting for those uncompilable errors a less tedious job.