Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How To Prevent AppleScript Formatting Preferences from Reverting to Default

How can I prevent the AppleScript syntax formatting, that is set in Preferences, from reverting to the default, or older settings?


Running Mavericks (10.9.5)


This is happening on several (all) of my Macs (MBA-13 2012, MBP-15R 2013).

I go to AppleScript > Preferences > Formatting, and change the syntax font/colors to something I prefer.

Click "Apply", and close the Pref window.

Everything looks good.

I can quit and restart AppleScript numerous times throughout the day, and my changes are retained.


But, when I put my Mac to sleep, and come back the next day, often, but not always, the syntax formatting will have reverted to old settings without me making any changes to Preferences.


How can I prevent this? How can I make sure the AppleScript > Preferences > Formatting stays the same until I make a change?


TIA for your help.

MacBook Pro (Retina, 15-inch, Early 2013), OS X Mavericks (10.9.5)

Posted on Aug 1, 2015 5:52 PM

Reply
14 replies

Aug 2, 2015 4:58 PM in response to JMichaelTX

Short answer - you can't (normal options such as locking the preferences file or making it read-only don't work). My guess is that you are also using Xcode or something else that uses the formatting preference, such as a Quicklook plugin, since it doesn't seem to happen that much if you aren't.

What I have been doing for the last couple of OS versions (this has been around for quite a while) is to get the formatting the way I want, make a copy of the com.apple.applescript.plist file in the ~/Library/Preferences folder, and use a script to restore from that file when the formatting decides to revert to the default.

Nov 18, 2015 3:06 PM in response to red_menace

red_menace wrote:


What I have been doing for the last couple of OS versions (this has been around for quite a while) is to get the formatting the way I want, make a copy of the com.apple.applescript.plist file in the ~/Library/Preferences folder, and use a script to restore from that file when the formatting decides to revert to the default.


I had been using this approach as well. But now, in Yosemite 10.10.5, I have to restart my MBP-15R to get the Script Editor to use my copy of the plist file, which, BTW, for Script Editor in Yosemite is now:

com.apple.ScriptEditor2.plist

This, of course, is a real PITA, especially now that the SE is reverting almost every day.


Where is the actual default settings stored? Seems like that is the file we need to change to keep SE from reverting to the app defaults.


Is the only way to get this really fixed to submit feedback to Apple?

Nov 19, 2015 5:52 PM in response to JMichaelTX

If you are replacing the plist by just copying over the file, that won't work - preferences property lists are cached by the system. The proper method is to use defaults.


I create a copy of the formatting preferences with the name "com.apple.applescript copy.plist" and leave it in the preferences folder (the formatting preferences are in a different file than the regular Script Editor preferences). The following script is then used to copy the contents of the backup file (or the clipboard) over the original file:



set originalPlist to "com.apple.applescript" -- Script Editor formatting

set theChoice to button returned of (display alert "               -- Defaults Update --" message "This script will reset the specified property list from a backup copy in the same folder or from the clipboard:" & return & return & originalPlist & return buttons {"Cancel", "Clipboard", "Backup"} cancel button "Cancel" default button "Cancel" as warning)

if theChoice is "Backup" then -- read backup copy
  set duplicatePlist to originalPlist & "\\ copy"
  set theContents to (do shell script "defaults read " & duplicatePlist)
else
  set theContents to the clipboard
end if

do shell script "defaults write " & originalPlist & space & quoted form of theContents


I'm pretty sure this is still an open bug, but you can always send feedback to Apple.

Nov 18, 2015 7:17 PM in response to red_menace

red_menace wrote:


I create a copy of the formatting preferences with the name "com.apple.applescript copy.plist"



@red_menace,


Thank you very much for all your help.


However, I am confused about the backup file name.

You state in your post it should be:

"com.apple.applescript copy.plist"


But then in your script, you have these statements:

set originalPlist to "com.apple.applescript"
set duplicatePlist to originalPlist & "\\ copy"

which results in a value of:

"com.apple.applescript\ copy"

So the calculated backup file name seems different from the one you stated in your post.

Please advise as to the correct name of the backup file, and confirm the script calculations.

Thanks.

Nov 19, 2015 5:51 PM in response to red_menace

red_menace wrote:


The backslash is there to escape the space for the shell script, . . .


Thank you so much for taking the time to make it clear to me. I really appreciate your patience.

Perhaps most others would have instantly seen your intent to escape the space, but I seem to always be challenged by the many ways paths are handled in AppleScript.

Nov 20, 2015 4:51 PM in response to red_menace

@red_menace, and all interested parties:


I just wanted to let everyone know that the script provided by @red_menace works perfectly.


Today, the Script Editor lost my preferred formatting, reverting back to its defaults.

Here's how I fixed it immediately, with no reboot needed:

  1. Several days ago when my SE formatting prefs were in order, using the Finder, I simply made a copy of "com.apple.applescript.plist" file in my ~/Library/Preferences folder by doing a CMD-C then CMD-V.
  2. This produced the file "com.apple.applescript copy.plist"
  3. I saved the script from @red_menance to my ~/Library/Scripts folder.
  4. Today when I noticed my prefs had been lost, I quit Script Editor
  5. In the Finder, I selected the "com.apple.applescript.plist" file -- don't know that this is necessary, just being cautious.
  6. Ran the script from @red_menance from my Mac menu Scripts menu
  7. Selected the choice to restore from "Backup"
  8. That's it!


As soon as I opened SE, I saw that my prefs had been restored!


My sincere thanks and gratitude to @red_menace 😎

Nov 20, 2015 6:06 PM in response to red_menace

@red_menace, with your permission, I'd like to post this linked script (zip file) to MacScripter.net (with links to it in several other forums) to increase the awareness of all Mac script developers on how to deal with this issue.


This script is 99% as you wrote it, with some minor mods to the display alerts to clarify the process, and I added a detailed header comments providing instructions on how to use.


BTW, as I now understand it, it is NOT necessary to select the file in Finder before running the script.

Is this correct?


Thanks again.


JMichael

Jul 16, 2016 11:48 PM in response to JMichaelTX

It turns out that the problem is caused by the choose application Standard Addition. It's completely replacing the com.apple.applescript preferences when it saves its window layout, discarding the formatting preferences and anything else stored there that it doesn't write.


Script Editor’s File > Open Dictionary command also uses choose application to present its UI.


So, as long as you don't do those things you shouldn't see the formatting preferences get reset, and if you're using the suggested script to save/restore the preferences, you'll want to restore them after running a script with choose application or using Open Dictionary.

Jul 17, 2016 7:21 AM in response to Xtra Crispy

It turns out that the problem is caused by the choose application Standard Addition.


And so it is! I don't normally use that command, or open dictionaries from the Script Editor (I keep HTML versions handy so the applications don't open). I do jump back and forth from Xcode on occasions, so there may still be something related going on there, but that definitely does it. Have you provided feedback or filed a bug report with Apple?

How To Prevent AppleScript Formatting Preferences from Reverting to Default

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.