• 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: I made a nightmare
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I made a nightmare


  • Subject: Re: I made a nightmare
  • From: Yvan KOENIG <email@hidden>
  • Date: Thu, 10 Dec 2015 14:11:49 +0100


Le 2015/12/10 à 12:15, Shane Stanley <email@hidden> a écrit :

On 10 Dec 2015, at 9:15 PM, Yvan KOENIG <email@hidden> wrote:

Here is a version which behaves well.

I suspect you could simplify things a bit with:

set movablePaths to (POSIX path of files of aSubfolder whose visible is true and name contains keyName)

And I think it would be preferable to move the "do shell script" outside the tell block.

-- 

At first, I used set movableFiles to files of a subfolder whose visible is true and name contains "Staff_01"
and it returned nothing.

This is why I split the task in two ones.

I made a new attempt and it worked so I rewrote the beast :

--set sourcefolder to (path to desktop as text) & "formoosmahna:" as alias
--set keyName to "staff_01"

set sourceFolder to choose folder
set keyName to text returned of (display dialog "Type a folder name" default answer "Staff_01")

tell application "System Events"
set theSubFolders to folders of sourceFolder
repeat with aSubfolder in theSubFolders
set movablePaths to (POSIX path of files of aSubfolder whose visible is true and name contains keyName)
if movablePaths is not {} then
set dest to (path of aSubfolder as text) & keyName & ":"
if not (exists folder dest) then
make new folder at end of aSubfolder with properties {name:keyName}
end if
set posixDest to quoted form of (get POSIX path of disk item dest)
repeat with aFile in movablePaths
set contents of aFile to quoted form of contents of aFile
end repeat
set qSource to my recolle(movablePaths, space)
tell me to do shell script "mv " & qSource & space & posixDest
end if
end repeat
end tell # System Events

#=====

on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle

#=====


As you may see, this time I call do shell script only once for each subfolder.
I put tell me to in front of do shell script to play safety but the script work without it.

I built a variant using mkdir but I was forced to reintroduce the quotePOSIXit handler.

set sourcefolder to (path to desktop as text) & "formoosmahna:" as alias
set keyName to "staff_01"

(*
set sourceFolder to choose folder
set keyName to text returned of (display dialog "Type a folder name" default answer "Staff_01")
*)
tell application "System Events"
set theSubFolders to folders of sourcefolder
repeat with aSubfolder in theSubFolders
set movableFiles to (files of aSubfolder whose visible is true and name contains "Staff_01") --keyName)
set movablePaths to (POSIX path of files of aSubfolder whose visible is true and name contains keyName)
if movablePaths is not {} then
set dest to (path of aSubfolder as text) & keyName & ":"
set posixDest to my quotePOSIXit(dest) # I didn't found a valid syntax without the handler. They failed when the folder wasn't existing.
do shell script "mkdir " & posixDest
repeat with aFile in movablePaths
set contents of aFile to quoted form of contents of aFile
end repeat
set qSource to my recolle(movablePaths, space)
tell me to do shell script "mv " & qSource & space & posixDest
end if
end repeat
end tell # System Events

#=====

on quotePOSIXit(aPath)
return quoted form of POSIX path of aPath
end quotePOSIXit

#=====

on recolle(l, d)
local oTIDs, t
set {oTIDs, AppleScript's text item delimiters} to {AppleScript's text item delimiters, d}
set t to l as text
set AppleScript's text item delimiters to oTIDs
return t
end recolle

#=====



Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) jeudi 10 décembre 2015 14:11:44





 _______________________________________________
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

References: 
 >I made a nightmare (From: Yvan KOENIG <email@hidden>)
 >Re: I made a nightmare (From: "S. J. Cunningham" <email@hidden>)
 >Re: I made a nightmare (From: Yvan KOENIG <email@hidden>)
 >Re: I made a nightmare (From: Shane Stanley <email@hidden>)
 >Re: I made a nightmare (From: Yvan KOENIG <email@hidden>)
 >Re: I made a nightmare (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Finder Shows No Windows when Hidden
  • Next by Date: Re: Finder Shows No Windows when Hidden
  • Previous by thread: Re: I made a nightmare
  • Next by thread: Finder Shows No Windows when Hidden
  • Index(es):
    • Date
    • Thread