copying folders; converting strings into folder references

Hi all,

I’m currently trying to get this script to work…it was fine, until I changed the directories to look inside the app resources folder. Not sure why that would make Finder throw the error that the handler can’t handle objects of this class, but that’s what happens. I feel like I’m so close but so far lol Here’s the problem excerpt from my script:


tell application "Finder"
	set floTools to POSIX path of (path to me) & "Contents/Resources/Flo Tools.kmmacros"
	set templates to POSIX path of (path to me) & "Contents/Resources/Flo Tools"
	set source to templates
	set destination to POSIX path of (path to library folder from user domain) & "Application Support"
	duplicate source to destination with replacing
end tell

Hey There,

The Finder doesn’t like POSIX Paths. Use HFS paths instead.

In general it’s a good idea to place calls to osaxen (in this case StandardAdditions.osax’s “path to me”) outside of Application-Tell-Blocks too.


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.6 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Got it, thank you so much. For reference, my script now looks like this:


tell application "Finder"
	set floTools to (path to me) & "Contents:Resources:Flo Tools.kmmacros" as text
	set templates to (path to me) & "Contents:Resources:Flo Tools" as text
	set source to templates
	set destination to (path to library folder from user domain) & "Application Support" as text
	duplicate source to destination with replacing
end tell


You can’t duplicate paths. The way you’re forming them is also potentially problematic. Try this:

set templates to (path to me as text) & "Contents:Resources:Flo Tools"
set destination to (path to library folder from user domain as text) & "Application Support"
tell application "Finder"
	duplicate folder templates to folder destination with replacing
end tell

Awesome, thank you!

If you have installed the free BridgePlus.scptd library you may use :

use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set templates to (path to me as text) & "Contents:Resources:Flo Tools"
set destination to (path to library folder from user domain as text) & "Application Support:Flo Tools"
set {theResult, theError} to (current application's SMSForder's copyItemAt:(POSIX path of templates) toItem:(POSIX path of destination) replace:true |error|:(specifier))
if theResult as boolean is false then error (theError's localizedDescription() as text)

which will be faster than the Finder code.

https://www.macosxautomation.com/applescript/apps/BridgePlus.html

An alternate scheme would be to install the free FileManagerLib available at :
http://www.macosxautomation.com/applescript/apps/

use scripting additions
use framework "Foundation"
use FMLib : script "FileManagerLib"


set templates to (path to me as text) & "Contents:Resources:Flo Tools"
set destination to (path to library folder from user domain as text) & "Application Support:"
FMLib's copyItem:(POSIX path of templates) intoFolder:(POSIX path of destination) withReplacing:true

Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) dimanche 20 novembre 2016 18:53:39