• 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: Trying to move away from Finder...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Trying to move away from Finder...


  • Subject: Re: Trying to move away from Finder...
  • From: Shane Stanley <email@hidden>
  • Date: Wed, 1 Nov 2017 23:38:31 +1100

On 1 Nov 2017, at 11:11 pm, Jean-Christophe Helary
<email@hidden> wrote:
>
> I have a Finder window opened on a "job" in which there is a folder
> (originaux) that contains files.
> I'm creating a folder hierarchy inside that "job" and I want to copy files
> that are in "originaux" to one of its folders.

If you're happy to do it in AppleScriptObjC, this should give you most of what
you need. It deals in URLs; it could be done with POSIX paths, but URLs often
end up more convenient in the long run. The various method names should make it
reasonably obvious what they do.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

tell application "Finder" to set default_location to POSIX path of (target of
front window as alias)
-- make URLs
set default_location_url to current application's |NSURL|'s
fileURLWithPath:default_location
set originals_folder_url to default_location_url's
URLByAppendingPathComponent:"originaux"
set new_folder_url to default_location_url's
URLByAppendingPathComponent:"whatever"
-- make new folder
set fileManager to current application's NSFileManager's defaultManager()
set {theResult, theError} to fileManager's createDirectoryAtURL:new_folder_url
withIntermediateDirectories:true attributes:(missing value) |error|:(reference)
if theResult as boolean is false then error theError's localizedDescription()
as text
-- get contents of originaux
set contents_urls to fileManager's
contentsOfDirectoryAtURL:originals_folder_url includingPropertiesForKeys:{}
options:(current application's NSDirectoryEnumerationSkipsHiddenFiles)
|error|:(missing value)
-- move the files
repeat with one_url in contents_urls
        set destination_url to (new_folder_url's
URLByAppendingPathComponent:(one_url's lastPathComponent()))
        (fileManager's moveItemAtURL:one_url toURL:destination_url
|error|:(missing value))
end repeat


--
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>


 _______________________________________________
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: Trying to move away from Finder...
      • From: Jean-Christophe Helary <email@hidden>
References: 
 >Re: Trying to move away from Finder... (From: Shane Stanley <email@hidden>)
 >Re: Trying to move away from Finder... (From: Jean-Christophe Helary <email@hidden>)

  • Prev by Date: Re: Trying to move away from Finder...
  • Next by Date: Running scripts with Quicken 2017
  • Previous by thread: Re: Trying to move away from Finder...
  • Next by thread: Re: Trying to move away from Finder...
  • Index(es):
    • Date
    • Thread