Search code examples
applescriptinode

Hard link breaks after changing original (AppleScript .scpt) file


I have an AppleScript Library file (.scpt) saved in ~/Library/Script Libraries which I use to call handlers from, in other scripts. I want also want to keep that file as part of a git repository. So my idea was: create a hard link in ~/Library/Script Libraries to the file in my repository.

When I first open the hard link, I see the exact same result as when opening the original file in my repo.

Checking the hard link in the Terminal renders the following result:

-rw-r--r--@ 2 username  staff  50458 May 15 16:45 MyLibrary.scpt

Pay attention to the filesize and the number of hard links (2).

When I change something in the target file, the hard link doesn't work anymore. Even when I just open the .scpt file, and save it without a change, the hard link seems broken.

When I check the hard link in the Terminal, it shows the following:

-rw-rw-rw-@ 1 username  staff  0 May 15 16:45 MyLibrary.scpt

So it is 0 bytes and the number of hard link has been reduced to 1.

Why does this not work? Does saving the original file change the inode it refers to?


Solution

  • I ended up solving the problem by changing my AppleScript build system in Sublime Text.

    {
        "cmd": ["/usr/bin/osascript", "$file"],
    
        "variants": [
            {
                "name": "Script Library",
                "cmd": ["/usr/bin/osacompile", "-o", "/Volumes/harddisk/Users/username/Library/Script Libraries/$file_base_name.scpt", "$file"]
            }        
        ]
    }
    

    I edit the .applescript file, which is tracked in the repository. When I run the Build command, the .applescript file is compiled to its .scpt variant in the Script Libraries folder.