ScriptEditor: Concatenate path of a file

Hello there,

I'm writing a very simple script in ScriptEditor witch should just find a folder on desktop and move/copy it into another folder (that still on desktop).


I'm struggling on making the script work without giving it the direct path to the folder, I would like it to get the current user short name and calculate the path to the folder.


Right now I'm at this point:


tell application "Finder"

set _info to system info

set UserID to short user name of _info


set sourceFolder1 to POSIX file ("/Users/" & UserID & "/Desktop/PROVA")

set destination to POSIX file ("/Users/" & UserID & "/Desktop/TEST")


if exists sourceFolder1 then

copy sourceFolder1 to the destination

end if

end tell


This compile correctly but gives me the error:

"Finder got an error: Can’t get folder \"/Users/[userID]/Desktop/PROVA\"." number -1728 from file "Macintosh HD:Users:[userID]:Desktop:PROVA"


How can I solve this?

I'm new to this language so I might miss the correct syntax.


Thanks a lot for the help

Alessandro.

Mac mini, macOS High Sierra (10.13.6)

Posted on Sep 13, 2018 5:47 AM

Reply

Similar questions

3 replies

Sep 13, 2018 11:34 AM in response to bosco90

Here is some more information. Tested on macOS High Sierra 10.13.6 (17G65).


-- the path to desktop as text clause automatically gets the user's short name

-- into the POSIX file result. Trailing colons on POSIX file folder names are optional.

-- Script Editor : File menu : Open Dictionary : System Events : Disk-Folder-File Suite

-- has a list of these path to locations under the application resource name.

-- The use of the as alias clause tells AppleScript that the file/folder already exists, and

-- you would omit the as alias clause when the file/folder does not yet exist.


set sourceFolder to (path to desktop as text) & "PROVA:" as alias

set destFolder to (path to desktop as text) & "TEST:" as alias

display dialog (sourceFolder as text) & return & (destFolder as text)


tell application "Finder"

-- remove the '--' comment depending on move or duplicate requirement

-- move sourceFolder to destFolder with replacing

-- duplicate sourceFolder to destFolder with replacing and exact copy

end tell

return

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

ScriptEditor: Concatenate path of a file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.