• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: which is better: applescript "move" command or do shell script mv….?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: which is better: applescript "move" command or do shell script mv….?


  • Subject: Re: which is better: applescript "move" command or do shell script mv….?
  • From: Christopher Stone <email@hidden>
  • Date: Fri, 28 Jun 2013 15:45:38 -0500

On Jun 27, 2013, at 22:08, Dee Dee Sommers <email@hidden> wrote:
I have a workflow I would like to replace, that moves specific files from folder a to folder b.  The folders are on the same volume and in the same subdirectory.  Folder b will normally contain files with the same name as the ones I am moving.  I want to overwrite the existing files.
No name change.
______________________________________________________________________

Hey Dee Dee,

Well that's simple enough.  I'd stick with Applescript unless you have a problem.

-------------------------------------------------------------------------------------------

set destFldr to alias ((path to home folder as text) & "test_directory:move_dest:")
set srcFldr to alias ((path to home folder as text) & "test_directory:move_src:")

tell application "Finder"
set moveList to items of srcFldr as alias list
set movEdList to (move moveList to destFldr with replacing) as alias list
end tell

-------------------------------------------------------------------------------------------

Will there be more than those 4 files in the folder you're moving from?

If so then you may need to create an alias list including just those 4 files.  (Aliases are better than Finder-references.)

You can address them directly, or you can do something like this:

-------------------------------------------------------------------------------------------

set destFldr to alias ((path to home folder as text) & "test_directory:move_dest:")
set srcFldr to alias ((path to home folder as text) & "test_directory:move_src:")
set nList to {"Test Find 01", "Test Find 02", "Test Find 03", "Test Find 04"}

tell application "Finder"
set moveList to (files of srcFldr whose name is in nList) as alias list
set movEdList to (move moveList to destFldr with replacing) as alias list
end tell

-------------------------------------------------------------------------------------------

Getting an alias-list from the Finder (unintuitively) is nearly always faster than getting Finder-references.

One advantage of using the Finder is that your result is a list of Finder-references you can use again.  Unfortunately this is one of those cases where you can't directly coerce to an alias-list.

Here's what I do IF I have a list of Finder-refs that I really need to be an alias list.  It's fast even with a large list.

-------------------------------------------------------------------------------------------

set nList to {"Test Find 01", "Test Find 02", "Test Find 03", "Test Find 04"}
set srcFldr to alias ((path to home folder as text) & "test_directory:move_src:")
tell application "Finder"
set moveList to (files of srcFldr whose name is in nList)
repeat with i in moveList
set contents of i to contents of i as alias
end repeat
end tell
moveList

-------------------------------------------------------------------------------------------

For really big files it's possible that mv will be faster than the Finder.

This could be written more succinctly of course, but I've drawn it out for the example value:

-------------------------------------------------------------------------------------------

# For easy editing:
set nList to items 1 thru -2 of {¬
"Test Find 01", ¬
"Test Find 02", ¬
"Test Find 03", ¬
"Test Find 04", ¬
""}

set destFldr to quoted form of POSIX path of ((path to home folder as text) & "test_directory:move_dest:")
set srcFldr to quoted form of POSIX path of ((path to home folder as text) & "test_directory:move_src:")
repeat with i in nList
set contents of i to quoted form of contents of i
end repeat
set AppleScript's text item delimiters to " "
set nList to nList as text

set _cmd to "
cd " & srcFldr & ";
mv " & nList & " " & destFldr

do shell script _cmd

-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: which is better: applescript "move" command or do shell script mv….?
      • From: Dee Dee Sommers <email@hidden>
References: 
 >which is better: applescript "move" command or do shell script mv….? (From: Dee Dee Sommers <email@hidden>)

  • Prev by Date: Re: getting time to next Time Machine backup and other information?
  • Next by Date: Re: Changes in 10.8
  • Previous by thread: which is better: applescript "move" command or do shell script mv….?
  • Next by thread: Re: which is better: applescript "move" command or do shell script mv….?
  • Index(es):
    • Date
    • Thread