Duplicating a Hidden File

I’m having a very difficult time trying to copy files w/replacing.

Source File: /Users/margehomer/Library/Containers/EnvelopeMagic/Data/Library/Application Support/EnvelopeMagic/EnvelopeMagic.sqlite-shm

Destination File: /Users/margehomer/Dropbox/EnvelopeMagic/EnvelopeMagic.sqlite-shm

Any help (apparently I’m not done learning) would be appreciated.

OK, I think I may actually be getting somewhere. I have the following script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to "Users/margehomer/Library/Containers/EnvelopeMagic/Data/Library/Application Support/EnvelopeMagic/EnvelopeMagic.sqlite-shm"
	set destinationFolder to (choose folder)
	duplicate theFile to destinationFolder
end tell

But when run I get the following error (screenshot).

Any help/hint appreciated.

Two things…

First, you have a typo with theFile… the string should begin with a ‘/’. Otherwise (I think) the behaviour is undefined.

Second, you’re working with two styles of file references.

You provide a posix path style reference in theFile but an alias reference in destinationFolder.

I would suggest working with aliases as the Finder doesn’t seem to support posix styles very well.

use scripting additions

tell application "Finder"
	set theFile to "/Users/margehomer/Library/Containers/EnvelopeMagic/Data/Library/Application Support/EnvelopeMagic/EnvelopeMagic.sqlite-shm"
	set theFile to (POSIX file theFile) as alias
	
	set destinationFolder to (choose folder)
	
	duplicate theFile to destinationFolder
end tell

I left the script you provided as it is, and it threw an error (screenshot).

This script works, if I copy the file from it’s hidden location to the Desktop. Possibly there’s something about the location of the file (normally hidden) that’s causing the issues.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to (choose file)
	set destinationFolder to (choose folder)
	duplicate theFile to destinationFolder
end tell

I’ve come up with a solution using Apple’s Automator. Works like a charm, so there’s no longer an issue with trying to find an AppleScript solution.

No, the Finder ignores hidden files by default but there is a flag in choose file to show them

set theFile to (choose file with invisibles)

Yet another thing learned, thank you. The script below works perfectly!

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to (choose file with invisibles)
	set destinationFolder to (choose folder)
	duplicate theFile to destinationFolder
end tell

Even though I’ve found a solution with Automator, I kept trying to find a solution using AppleScript. With enough Googling I’ve come up with this, and it works. I’d be interested in knowing why from those much more experienced than myself.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to alias "Macintosh HD:Users:margehomer:Library:Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:EnvelopeMagic.sqlite-shm"
	set destinationFolder to (choose folder)
	duplicate theFile to destinationFolder
end tell

tell application "Finder"
	set theFile to alias "Macintosh HD:Users:margehomer:Library:Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:EnvelopeMagic.sqlite-wal"
	set destinationFolder to (choose folder)
	duplicate theFile to destinationFolder
end tell

Why not duplicating both files simultaneously?

set envelopeMagicBaseFolder to (path to library folder from user domain as text) & "Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:"

tell application "Finder"
	set sqliteFiles to every file of folder envelopeMagicBaseFolder whose name begins with "EnvelopeMagic.sqlite-"
	set destinationFolder to (choose folder)
	duplicate sqliteFiles to destinationFolder
end tell

I see by the script you just posted that you must have EnvelopeMagic installed as well, because the location to the folder is posted as:/Users/myname/Library/Application Scripts/org.hancu.EnvelopeMagic

The whole exercise here is because as of right now the developer has not implemented iCloud sync, it’s planned, but some time in the future. I have two Mac systems and without iCloud sync, the only way to sync any updates on either machine was to use Dropbox. So. one Automator (and now possibly AppleScript) application copies the two files needed to sync to Dropbox, and then when on the other system an Automator application copies the two files from Dropbox to the EmvelopeMagic Library location.

As for doing both files at once, only two files are required to sync any changes (see screenshot). The “EnvelopeMagic.sqlite” is not needed.
Screenshot

My suggestion duplicates any file which begins with EnvelopeMagic.sqlite- (note the trailing hyphen) these are the .shm and .wal files.

And path to library folder from user domain as text on your machine represents Macintosh HD:Users:margehomer:Library:

1 Like

Thank you for the explanation, I’ll probably try working your changes into the two working scripts I now have.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to alias "Macintosh HD:Users:margehomer:Library:Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:EnvelopeMagic.sqlite-shm"
	set destinationFolder to "Macintosh HD:Users:margehomer:Dropbox:EnvelopeMagic"
	duplicate theFile to destinationFolder
end tell

tell application "Finder"
	set theFile to alias "Macintosh HD:Users:margehomer:Library:Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:EnvelopeMagic.sqlite-wal"
	set destinationFolder to "Macintosh HD:Users:margehomer:Dropbox:EnvelopeMagic"
	duplicate theFile to destinationFolder
end tell
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	set theFile to "Macintosh HD:Users:margehomer:Dropbox:EnvelopeMagic:EnvelopeMagic.sqlite-shm"
	set destinationFolder to alias "Macintosh HD:Users:margehomer:Library:Containers:EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic"
	duplicate theFile to destinationFolder
end tell

tell application "Finder"
	set theFile to "Macintosh HD:Users:margehomer:Dropbox:EnvelopeMagic:EnvelopeMagic.sqlite-wal"
	set destinationFolder to alias "Macintosh HD:Users:margehomer:Library:Containers:EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic"
	duplicate theFile to destinationFolder
end tell

This merges your scripts into one and asks for the copy direction

set envelopeMagicBaseFolder to (path to library folder from user domain as text) & "Containers:org.hancu.EnvelopeMagic:Data:Library:Application Support:EnvelopeMagic:"
set dropboxFolder to (path to home folder as text) & "Dropbox:EnvelopeMagic:"

tell application "Finder"
	activate
	display dialog "Copy the database files from EnvelopeMagic to Dropbox or vice versa" buttons {"Cancel", "EnvelopeMagic → Dropbox", "Dropbox → EnvelopeMagic"}
	if button returned of the result is "EnvelopeMagic → Dropbox" then
		set sqliteFiles to every file of folder envelopeMagicBaseFolder whose name begins with "EnvelopeMagic.sqlite-"
		duplicate sqliteFiles to folder dropboxFolder
	else
		set sqliteFiles to every file of folder dropboxFolder whose name begins with "EnvelopeMagic.sqlite-"
		duplicate sqliteFiles to folder envelopeMagicBaseFolder
	end if
end tell

1 Like