• 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: duplicate command
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: duplicate command


  • Subject: Re: duplicate command
  • From: "koenig.yvan" <email@hidden>
  • Date: Fri, 12 Apr 2013 19:16:28 +0200


Le 12/04/2013 à 18:31, Simon Topliss <email@hidden> a écrit :

On 12 Apr 2013, at 16:31, koenig.yvan <email@hidden> wrote:

(path to desktop as text) & "get archives AppleScript - stripped.scpt"
set sourcePath to quoted form of POSIX path of result
"Macintosh HD:"
set targetPath to quoted form of POSIX path of result

Here's a tip for those playing along at home…

Never, ever write code like the above. Always be explicit in your variable declarations. The correct way to write this is:

set sourcePath to quoted form of POSIX path of  ((path to desktop as text) & "get archives AppleScript - stripped.scpt")
set targetPath to "/"

Yvan's code is a bug waiting to happen. 

JUst for see, I added two log instructions in my original code :

(path to desktop as text) & "get archives AppleScript - stripped.scpt"
set sourcePath to quoted form of POSIX path of result
log sourcePath
"Macintosh HD:"
set targetPath to quoted form of POSIX path of result
log targetPath
do shell script "cp -np " & sourcePath & space & targetPath with administrator privileges


At execution, the events area displayed :

tell current application
path to desktop as text
--> "Macintosh HD:Users:yvankoenig:Desktop:"
(*'/Users/yvankoenig/Desktop/get archives AppleScript - stripped.scpt'*)
(*'/'*)
do shell script "cp -np '/Users/yvankoenig/Desktop/get archives AppleScript - stripped.scpt' '/'" with administrator privileges
--> ""
end tell

Résultat :

""


As far as I know, when AppleScript execute the instruction :

set sourcePath to quoted form of POSIX path of ((path to desktop as text) & "get archives AppleScript - stripped.scpt"),
it compute the value (path to desktop as text) & "get archives AppleScript - stripped.scpt" and store it in the variable sourcePath
which is exactly what my code is doing.

I'm just lazy and take care to keep instructions identical when it's possible.

Sometimes, I'm so lazy that I code :

(path to desktop as text) & "get archives AppleScript - stripped.scpt"
set sourcePath to quoted form of POSIX path of result

"Macintosh HD:"
quoted form of POSIX path of result
do shell script "cp -np " & sourcePath & space & result with administrator privileges

And I'm interested to learn what would be dangerous with that.


Yvan KOENIG (VALLAURIS, France) vendredi 12 avril 2013 19:16:23



 _______________________________________________
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: duplicate command
      • From: Simon Topliss <email@hidden>
    • Re: duplicate command
      • From: Christopher Stone <email@hidden>
References: 
 >Re: duplicate command (From: Robert Cuilla <email@hidden>)
 >Re: duplicate command (From: Luther Fuller <email@hidden>)
 >Re: duplicate command (From: "koenig.yvan" <email@hidden>)
 >Re: duplicate command (From: Luther Fuller <email@hidden>)
 >Re: duplicate command (From: "koenig.yvan" <email@hidden>)
 >Re: duplicate command (From: Simon Topliss <email@hidden>)

  • Prev by Date: Re: duplicate command
  • Next by Date: XML tags as characters in InDesign 5.5
  • Previous by thread: Re: duplicate command
  • Next by thread: Re: duplicate command
  • Index(es):
    • Date
    • Thread