• 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 09:41:32 +0100


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

On 10 Dec 2015, at 4:10 AM, Yvan KOENIG <email@hidden> wrote:

What is puzzling is not the fact that set dest to quoted form of POSIX path of ((sourcefolder as text) & theName)
fails in a System Events block.
I know for months that we aren’t supposed to use OSAX features in a tell application block.
But I know also that Apple explained that 
tell me to  set dest to quoted form of POSIX path of ((sourcefolder as text) & theName)
is THE way to get rid of this rule.

So, the official scheme doesn’t work.

You're overlooking the fact that System Events also defines the term POSIX path, and I suspect that's the cause of what you are seeing in this case. 

As long as the item at the path exists, you can use this without error:

tell application "System Events"
set dest to POSIX path of disk item ((sourcefolder as text) & theName)
end tell

The other alternative is ensure that System Events's POSIX path is not used:

tell application "System Events"
using terms from scripting additions
set dest to POSIX path of ((sourcefolder as text) & theName)
end using terms from
end tell

As a side note to your actual code, using either the shell's mkdir or ASObjC is easier in this situation because you don't need to check whether the folder already exists; they just make it if it's not there already:

use scripting additions
use framework "Foundation"

set theResult to current application's NSFileManager's defaultManager()'s ¬
createDirectoryAtPath:(POSIX path of ((sourcefolder as text) & theName)) ¬
withIntermediateDirectories:true attributes:(missing value) |error|:(missing value)

Thanks Shane.
I forgot that POSIX path is also defined by System Events.
The relevant part of my script is :

if movableFiles 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 my quotePOSIXit(dest) -- finally my best choice
tell application "Script Editor"
set posixDest to quoted form of POSIX path of dest # Here it works. Here the folder exists
end tell.
repeat with aFile in movableFiles
log (get class of aFile) --> (*file*)
-- set qSource to my quotePOSIXit(path of aFile) -- finally my best choice
tell application "Script Editor"
set qSource to quoted form of (get POSIX path of file (path of aFile)) -- Here the file exists
# I don't understand why but, aFile which is a file isn't one for POSIX path
set qSource to quoted form of (get POSIX path of aFile) --> error "Il est impossible de rendre file \"SSD 500:Users:ME:Desktop:formoosmahna:sub1:1 Amazing (feat. Laughton Kora)staff_01.wav\" of application \"System Events\" dans le type attendu." number -1700 from file "SSD 500:Users:ME:Desktop:formoosmahna:sub1:1 Amazing (feat. Laughton Kora)staff_01.wav"
end tell
do shell script "mv " & qSource & space & posixDest
end repeat
end if

As you may see, in both calls, the targeted items exist.
I choose to create the folder at first to be sure that it exists to be able to define its POSIX path only once.


Yvan KOENIG running El Capitan 10.11.2 in French (VALLAURIS, France) jeudi 10 décembre 2015 09:41:26





 _______________________________________________
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>)

  • Prev by Date: Filemaker - commit or select no cell
  • Next by Date: Re: Filemaker - commit or select no cell
  • Previous by thread: Re: I made a nightmare
  • Next by thread: Re: I made a nightmare
  • Index(es):
    • Date
    • Thread