Keeping Scripts (and More) In Sync

How do y’all keep your scripts in sync across multiple macs, so they’re always where they’re expected for KM, FastScripts, etc.?

dropbox folder! and there’s an alias to dropbox in my documents folder, so referencing it from a home folder path works…

1 Like

I make extensive use of DropBox, symlinks, and aliases.

##dropbox

  • I use DB to sync all of my apps data across all of my Macs, and even with my iOS devices.
  • I have set the Dropbox root folder on all of my Mac in the same exact locatiion, so it, and all subfolders/files, will have the exact same path on all my Macs
    • I chose /Users/Shared/Dropbox
    • I am the only user of my Macs, so being in the "Shared" folder is not an issue for me
    • But you could put it anywhere you like, as long as it is the same on all Macs.
  • This has worked flawlessly for several years
  • The sync seems to be near instantaneous (as soon as you save a file update), but I am conservative, and generally make sure I close all apps on one Mac before opening then on another.

###SymLinks

  • See What Are Aliases, Symbolic Links, and Hard Links in Mac OS X?
  • I mostly use symlinks (rather than aliases)
  • I have symlinks for all of my AppleScript system related folders, to a folder inside of my DropBox setup
    • For example:
      .
      EDIT: 2017-03-13 12:58 AM CT
      after double-checking, I realize that I have used this setup:
      • ~/Library/Scripts is an alias to my DropBox folder
      • This is necessary because FastScripts does NOT recognize symlinks.
        .

The last folder in each path in this list is a symlink or alias to the folder in my DropBox folders:

~/Library/Application Support/Script Editor    [symlink]
~/Library/Script Libraries    [symlink]
~/Library/Scripts     [alias]

###Procedure to Setup SymLinks

  1. FIRST, backup ALL of the existing related folders in your ~/Library that you are going to replace with sym links
    .
  • Create the folder setup in your DropBox folders.

    • It can be at any level, but I suggest they be in a parent folder that also contains all of your other script files, to facilitate searches.
    • For example, all of the symlinks above link to a sub-folder of this folder:
      /Users/Shared/Dropbox/DEV/Linked Folders
    • See my example folder organization below.
      .
  • In the Dropbox parent folder of the target folder, create the SymLlink file.

  • Replace the corresponding folder in ~/Library with the SymLink file.

    • One easy way to do this is to rename the existing folder by appending " - OLD" to the end of it.
    • Then make sure you move the symlink file to the SAME parent folder as the on you are replacing.
      .
  • Take it slow. Do one folder at a time, and test to make sure it works like you expect it to.

    • Put one or two files in the DropBox setup, and test access from Script Editor, like using a script library.
    • Put some scripts in the Dropbox Scripts folder, and make sure you can see them from the Apple Script Menu bar.
      .
  • If you have ANY questions or doubts, ask before you proceed.

Here's a general way to organize your scripts and development:

##example Folder Organization in DropBox

/Users/Shared/Dropbox
	/DEV
		/Linked Folders
			/Script Editor
			/Script Libraries
			/Scripts
		/My AppleScripts
		/My JXA Scripts
		/My KM
			/Scripts
			/Macros
			/Misc
			/Resources
			etc
		/Projects
		etc.

Note that all of your scripts are contained within the DEV folder.
So, if you set the Finder's target to DEV, then you can do a search for all scripts it contains.
For example:
kind:script @date
would find all of my script files that have the text tag "@date" in the name or contents of the script file, all within the /Users/Shared/Dropbox/DEV folder.

###Use in Keyboard Maestro
Now, I can reference any of these scripts by path in a KM Execute AppleScript Action, and it will be found on all of my Macs.
My usual convention is to put all scripts (regardless of kind) used by KM in the My KM/Scripts folders. I do this whether I use the script path, or just the script text, in the KM Action. I always develop and test all scripts in a file using Script Debugger 6 (or Script Editor). Then, if it is something I might share with others, I will change the Execute Script action to use "text" instead of "file".

Good luck to all who want to use this method.
Please feel free to ask any question.

4 Likes

This is great! While I’m using aliases for now–it seems fastscripts doesn’t like symlinks–I’ve put your DB folder structure to great use. Thank you!

Just a tip (assuming you are still using LaunchBar):

You can also create symlinks by dragging files onto a LaunchBar-selected folder:

This way you can also create Aliases or Hard Links, or – sometimes a crucial difference – relative symlinks. Alternatively to dropping files it works also via LB’s “Send” (i.e. selecting a file in LB and then sending it to a folder with the Tab key). Works also for multiple selections.

1 Like

Thanks, @Tom. I continue to learn more about LB from you than any other source. LB should hire you to write their Ver 6 documentation.

1 Like

Tom, how do you get this list in LB?

When I type "make" in the LB prompt, I get:

Option 1 (with Finder selection):

  1. Select a folder in the Finder.
  2. Press your Instant Send key (as set in LB’s preferences > Shortcuts)
  • You will see now that the folder has been “sent” to LB; it appears in the LB window.
  1. Drag any file onto that folder in the LB window.
  • Now you get the Move/Copy/Alias/Symlink/Hardlink prompt as shown in my screenshot.
  1. Long-press the number (on your keyboard) which is indicated after the desired action (e.g. 5 for Absolute Symlink)
  • The symlink is now created in the LB-selected folder.

Note:

If the LB window closes before you can drag a file onto it (for example because you open another window in the Finder, etc.), then just bring up the LB window with your normal LB key (not the Instant Send key) and the afore sent folder will still be in LB’s window, so that you can drag now your file onto it.

Hint:

By holding down certain modifier keys while dragging, you can invoke the desired action without having to select it via a number key. (E.g. the Ctrl key for making an absolute symlink; See LB Help, Actions > Drag and Drop)

Another hint:

Instead of dragging the file with the mouse onto the folder in the LB window, you can also simulate a drag by pressing ⌘D (while the file is selected in the Finder and LB’s window is open).

Option 2 (staying in LB, completely without Finder):

  1. In LB, navigate to the file you want to move/copy/symlink/hardlink.
  2. Once you have found the file press the Tab key.
  • Now you are in “Send” modus.
  1. Still in LB, Navigate to the destination folder.
  2. Once you have found the destination folder, press Return.
  • Now will see the Move/Copy/Alias/Symlink/Hardlink prompt as shown in my screenshot.
  1. Long-press the number (on your keyboard) which is indicated after the desired action (e.g. 5 for Absolute Symlink)
  • The symlink is now created in the destination folder.

Sounds complicated. But it isn’t. (Once you have understood how it works :wink:)

1 Like

Many Thanks Tom. Once again, you have taught me about LB.

###To All Other Readers
In case it was not obvious from @Tom's excellent instructions, here is how you would create a symlink for the Script Libraries folder to your DropBox folder:

  1. In the Finder, goto ~/Library (you can use ⌘⇧G for this).
  2. Rename "Script Libraries" to "Script Libraries OLD" IF it exists
    (otherwise, skip this step)
  3. Since "Library" is a hidden folder we have to use a workaround to get it in the LB prompt:
  • Select any folder in ~/Library, and press the LB Instant Send key
  • This will show that folder in the LB prompt
  • Press the LEFT ARROW key twice to backup to show the ~/Library folder in the LB prompt
  1. In the Finder, drag your Dropbox folder
    /Users/Shared/Dropbox/DEV/Linked Folders/Script Libraries
    (or whatever folder you are using)
    on top of the LB prompt
  • If the LB prompt disappears while you are navigating to this folder, just press your normal LB hotkey to show it.
  1. In the LB prompt, select the "Make Symbolic Link (Absolute)" choice, and press RETURN
  2. This will create the symlink in the ~/Library folder with the name of "Script Libraries"
  3. If you linked to a folder of a different name, you will need to goto ~/Library folder and rename it to "Script Libraries".

That looks a lot harder than it actually is, but I wanted to give detailed instructions to be clear. As Tom says, once you have done this once, it will seem easy.

Thanks again, Tom.

I'm having some trouble getting both Script Debugger and FastScripts to recognize the Scripts or Script Libraries folders. Script Debugger doesn't like an aliased folder, and FastScripts doesn't like a symlinked folder. How are y'all getting these two apps to recognize the same linked folders synced across different macs?

I misspoke (miswrote) earlier when I said I mostly use symlinks.
Your posts refreshed my memory, and after double-checking, I realize that I have used this setup:

  • ~/Library/Scripts is an alias to my DropBox folder
  • ~/Library/Script Libraries is a symlink to my DropBox folder.

You are correct, FastScripts does NOT recognize symlinks.
But, since the Scripts folder is an alias it works fine. Sorry for any confusion I caused.

I just tested a script in the DropBox Scripts folder, which uses a handler in my script library (stored in the DropBox Script Libraries folder), and it worked fine, for either running the script via FastScripts (with Chrome as frontmost app), OR from SD6.

Have you tried such a test?

Ah! I was stuck in an all-or-nothing mentality. Thank you.

1 Like

###Syncing LaunchBar
AFAIK, LB does not directly (officially) support syncing among Macs.
But it appears that it could be done using a symlink.
I have NOT does this, so I can’t vouch for this method.

See:
Dropbox synchronization - LaunchBar Forum

Yes that's what I was reading. As I understand it the caveat is that you
cannot have LaunchBar open on both macs at once... which is my use case :slight_smile:
I'll have to do it manually I guess. Thank you!

If you have any of the apps/files that you are syncing, like KM for example, open on more than one Mac you are risking conflicts, maybe even corruption.

I have two Macros I always run when I switch Macs:

  • Sleep -- quits all apps and disconnects all external drives, then puts the Mac to sleep.
  • Wake -- auto-runs when the Mac is waken from sleep or is started/restarted. If my std apps are not running, then it opens these apps, and does some other stuff.

I think, what manfred means with “use” is ‘actively using LB’.

When you are (actively) using LB it will update the Habits.plist file in ~/Library/Application Support/LaunchBar/. This is the file that gets updated when LB “learns” your typed abbreviations (not the fix abbreviations). So, of course, when you are typing something into LB at the same time on both machines you’ll have a sync conflict.

However, when LB is just open on both machines (running in the background, not actively used) then the only thing that gets updated – AFAIK – is the index. The index is located in ~/Library/Caches/at.obdev.LaunchBar, and you are not syncing it.

1 Like

Another thought:

Because of the aforementioned Habits file I would be hesitant to sync the whole ~/Library/Application Support/LaunchBar/ folder across machines. Since you most likely have different file paths and applications on different machines, logic says that by syncing you will contaminate the Habits file with invalid/undesired entries.

So, maybe the best would be to just sync specific files/folders in ~/Library/Application Support/LaunchBar/ , for example Actions, Snippets, etc.

On the other hand, if configuration and file structure of your both machines is quite the same, it may be desirable to have the Habits file synced…

1 Like

Both macs have the same username, and dammed near the same set of applications. I think they would only differ in desktop/documents contents, which is usually a handful of files at most (since I keep nearly everything in Dropbox). I wonder if that's similar enough?

After ensuring both macs have exactly the same apps, I think I will try archiving and then syncing the entire Application Support folder and see how that goes. If it fouls things up I will restore the folder and then sync only the Actions, Snippets, etc.

That’s not even necessary. (The Habits file stores paths with the tilde (~), not with the explicit username.)

Would be great if you report back your experiences. (I have never seriously synced LB with another Mac, but that’s probably because I work 95% of the time on only one Mac.)

Would you mind sharing (some version) these?