17.7 C
New York
Wednesday, November 6, 2024

macos – Copy or transfer recordsdata utilizing Finder, however from Terminal


To repeat or transfer file to a special folder utilizing Terminal, the plain means is to make use of the cp and mv instructions.

However for customers who typically put essential info within the “Feedback” part of the “Get Data” window of their recordsdata and folders, cp and mv have a disadvantage that feedback are typically misplaced.

The one dependable means I’ve discovered up to now to repeat/transfer recordsdata utilizing Terminal and protect feedback is to make use of AppleScript.

I’ve a number of snippets for that, however at the moment they work simply to display the thought, and that’s to say, they don’t seem to be a script that you need to use with arbitrary targets and locations like cpx . Right here they’re, simply in case, and although I might be very appreciated for assist to transform them right into a script that may work like cpx , this isn’t what my query is about.

Suppose you could have

~/
|- dir1/
   |- dir2/
   |  |- dir3/
   |  |- file
   |
   |- dir4/
      |- dir5/

Then:

to repeat the file to dir3, use:

osascript << SCRIPT
set currentFolder to "$(pwd)" as POSIX file as textual content
inform utility "Finder"
  duplicate file (currentFolder & "file") to folder (currentFolder & "dir3:")
finish inform
SCRIPT

to repeat it to dir4, use both

osascript << SCRIPT
set currentFolder to "$(pwd)" as POSIX file as textual content
set parentFolder to "$(dirname $PWD)" as POSIX file as textual content
inform utility "Finder"
  duplicate file (currentFolder & "file") to folder (parentFolder & "dir4:")
finish inform
SCRIPT

or

osascript << SCRIPT
set currentFolder to "$(pwd)" as POSIX file as textual content
inform utility "Finder"
  set parentFolder to (container of folder currentFolder) as textual content
  duplicate file (currentFolder & "file") to folder (parentFolder & "dir4:")
finish inform
SCRIPT

And right here is my query: Perhaps I overcomplicate issues and as a substitute of utilizing AppleScript, I can use one thing just like open -a ?

# this works. that is used to open a file utilizing a selected app
open -a  
# this does not work and only a demonstration of my thought
copy -a finder  

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles