• 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: Dee Dee Sommers <email@hidden>
  • Date: Sat, 29 Jun 2013 17:00:26 -0400

Hi Chris,
Wow.  This is awesome!  I guess it's THAT clear that I don't have a clue, what I'm doing, huh?
Anyway, I cannot tell you how much I appreciate the time you put into this explanation.  I have spent so much time and effort, trying to understand aliases and files and POSIX specifiers…..  I've printed the relevant pages out, from the Applescript Language Guide, I have beginner's guide to Applescript out from the library, I just purchased another Applescript book that I'm hoping will arrive soon…..  but your patient explanation with examples is the best I've seen thus far….. it gives me something more to study. 

The script I came up with (before I received your awesome advice) was just a very simple one:
tell application "Finder"
set sourceFldr to folder "Macintosh HD:Users:deedee:TestingStuff:Mass"
set destFldr to folder "Macintosh HD:Users:deedee:TestingStuff:daymass"


move every file of sourceFldr to destFldr with replacing


end tell

From your examples, though, I guess I need to modify the code some, huh? 
I then went further and tested for what happens if say, the source folder is empty (will the script error out?) no.

For at least the current time, I will want every file in the source folder moved, so that makes it pretty easy.  Also, currently, 4 is pretty much the number we anticipate for the foreseeable future.  All the files are .mp4 files, and the largest usually will be < 500 MB.  Up until now, the move is being handled with an Automator workflow.

Thank you again!
I hope I somehow come to understand the whys of how to address objects. 
Dee Dee


On Jun 28, 2013, at 4:45 PM, Christopher Stone wrote:

______________________________________________________________________

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: Christopher Stone <email@hidden>
References: 
 >which is better: applescript "move" command or do shell script mv….? (From: Dee Dee Sommers <email@hidden>)
 >Re: which is better: applescript "move" command or do shell script mv….? (From: Christopher Stone <email@hidden>)

  • Prev by Date: Re: Changes in 10.8
  • Next by Date: Re: which is better: applescript "move" command or do shell script mv….?
  • Previous by thread: Re: 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