문제

I'm attempting to move a folder to a package folder (a folder with an extension of .tblk).

Code:

tell application "Finder"

    set theFolder to (choose folder with prompt "Choose source folder" default location (path to downloads folder))

    set theResources to make new folder at theFolder with properties {name:"Resources"}

    set theContents to make new folder at theFolder with properties {name:"Contents"}

    move theResources to theContents

    set thePackage to make new folder at theFolder with properties {name:"package.tblk"}

    move theContents to thePackage -- error here

    set theConfigurations to (choose folder with prompt "Choose destination folder" default location (path to desktop folder))

    move thePackage to theConfigurations

end tell

Error:

Finder got an error: Can’t make document file "Package.tblk" of folder "Desktop" of folder "craibuc" of folder "Users" of startup disk into type folder.

If this line:

set thePackage to make new folder at theFolder with properties {name:"package.tblk"}

is changed to:

set thePackage to make new folder at theFolder with properties {name:"package"}

then the script works as expected.

Is there a better way to work with these types of folders?

도움이 되었습니까?

해결책

Refactored the code to create the package after the other work is completed. Used an alias to preserve the file reference after the folder's extension is changed:

tell application "Finder"

  set theFolder to (choose folder with prompt "Choose source folder" default location (path to downloads folder))

  set theResources to make new folder at theFolder with properties {name:"Resources"}

  set theContents to make new folder at theFolder with properties {name:"Contents"}
  move theResources to theContents

  set thePackage to make new folder at theFolder with properties {name:"Package"}
  move theContents to thePackage

  set thePackageAlias to thePackage as alias
  set the name extension of thePackageAlias to "tblk"

  set theConfigurations to (choose folder with prompt "Choose destination folder" default location (path to desktop folder))

  move thePackageAlias to theConfigurations

end tell
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top