1

I'm trying to modify /System/Library/ScriptingDefinitions/CocoaStandard.sdef. I want to do this because a lot of applications reference this file in their own scripting definitions, and I want to experiment with adding new stuff that will take effect in every application. Since scripting definition entries map directly to Cocoa objects and their methods, I figure this would be an effective way to mess with other applications' objects.

I rebooted to Recovery OS and ran the following commands in a terminal:

csrutil disable
umount "/Volumes/Macintosh HD"
mkdir /Volumes/mhd
mount /dev/disk3s1 /Volumes/mhd
cd /Volumes/mhd/System/Library/ScriptingDefinitions
mv CocoaStandard.sdef CocoaStandard.sdef.original
ln -s /Library/ScriptingDefinitions/CocoaStandard.sdef .
reboot

Note that I have already placed a copy of CocoaStandard.sdef in /Library/ScriptingDefinitions.

The problem I'm running into is that, despite disabling System Integrity Protection, once I reboot into macOS, the changes I made in /System/Library/ScriptingDefinitions have somehow been reverted. There is no CocoaStandard.sdef.original, and CocoaStandard.sdef is once again a regular file rather than a symbolic link.

How do I stop these changes from being reverted? Alternatively, if there is a better way to add custom scripting definitions to existing applications, that would work as well. (I tried directly adding entries to the .sdef inside a copy of the application, but then whenever I try to control that copy of the application using AppleScript, I get error -1728.)

4
  • What OS are you running? Note that macOS 11 (Big Sur) and later use cryptographic protection with a signed system volume - the read-only System volume is now sealed and will not accept any changes without a valid signature from Apple.
    – red_menace
    Jun 28, 2022 at 4:16
  • I think you should add changes to /Library/Scripting Additions, instead.
    – benwiggy
    Jun 28, 2022 at 6:45
  • @benwiggy: Will that let me control other applications' internal objects, like if I added stuff to an application's built-in .sdef file?
    – Sparkette
    Jun 28, 2022 at 16:09
  • I don't know, but the usual paradigm is to augment the system in /Library, not to modify the system.
    – benwiggy
    Jun 29, 2022 at 8:34

1 Answer 1

1

I read later that (like @red_menace pointed out in the comments) the behavior was caused by the sealed system volume. I haven't done this, but csrutil authenticated-root disable at the recovery terminal should prevent it from occurring. But according to this page, there are various reasons why that might not be desirable, especially for something that can be accomplished in other ways.

Specifically, the way I found that works was to create a disk image in Disk Utility, and then mount it at /System/Library/ScriptingDefinitions. This will temporarily replace the contents of the directory with the contents of the disk image without actually modifying anything on disk. The basic steps to do that are:

  1. Open Disk Utility.
  2. File->New Image->Blank Image...
  3. Set a smaller file size (I used 16 MB, though even that is an awful lot) and save the disk image. I saved it to the desktop as ScriptDefs.dmg.
  4. Place the modified CocoaStandard.sdef in the mounted disk image, and eject it.
  5. Open Terminal.
  6. hdiutil attach ~/Desktop/ScriptDefs.dmg
  7. Look at the list that appears, and find the /dev/disk#s# listed at the bottom.
  8. sudo mount -t apfs -o nobrowse /dev/disk#s# /System/Library/ScriptingDefinitions (replacing disk#s# with the values from above)

According to my testing, this will (understandably) fail with a "permission denied" error if System Integrity Protection is enabled, so you'll have to disable that first. Also, don't create a compressed DMG, because for whatever reason that'll fail with the same error even if SIP is off.

2
  • What was the outcome of modifying CocoaStandard.sdef ? Did it affect anything ?
    – CJK
    Jul 20, 2022 at 20:23
  • @CJK: Yes; it had the effect I was expecting, for the most part. I managed to make the toolbar in Messages customizable, though moving the buttons around resulted in a broken appearance and the changes didn't save. I just did that as a test, however.
    – Sparkette
    Jul 22, 2022 at 20:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .