편집 : 이미 automator를 사용하여 하위 폴더를 만들었습니다.
저는 현재 Android를 위해 디자인하고있는 디자이너입니다. Sketch App을 사용하여 모든 자산을 내 보내어 동일한 접미사 (예 : -xxxhdpi, -xxhdpi, -xhdpi, -hdpi, -mdpi)를 갖도록합니다.
파일의 예 : 스크린 샷 참조
폴더의 예 : 스크린 샷 참조
내가하려는 것은 이러한 모든 자산을 하위 폴더 (/ xxxhdpi, / xxhdpi 등)로 이동하고 접미사를 자르는 것입니다.
프로그래밍 / 애플 스크립팅에 대한 지식이 전혀 없어서 Automator를 사용해 보았습니다. 그러나 나는 상대 경로에 대한 한계를 발견했습니다. 많은 리소스를 검색 한 후 ( 파일을 찾아 다른 폴더로 이동하기위한 Applescript 찾기 및 Applescript : 폴더 / 하위 폴더 만들기 및 여러 파일 이동 포함 ). 그 라인이 무엇을하는지 잘 알 수 없기 때문에 다소 혼란 스럽습니다. 그러나 나는 이것을 생각 해냈다
tell application "Finder"
set assetsFolder to (target of front Finder window) as text
do shell script "cd " & (quoted form of POSIX path of assetsFolder) & "; "
set selectedItems to selection
repeat with this_item in selectedItems
if this_item's name contains "-xxxhdpi" then
set the theName to this_item's name
set the theSource to "-xxxhdpi"
set the theReplacement to ""
move this_item to folder "xxxhdpi" of folder assetsFolder
set name of this_item to my replace(theName, theSource, theReplacement)
end if
end repeat
end tell
on replace(theString, theSource, theReplacement)
set AppleScript's text item delimiters to theSource
set theItems to every text item of theString
set AppleScript's text item delimiters to theReplacement
return theItems as Unicode text
end replace
나는 이것을 먼저 테스트하기를 원하기 때문에 이것이 "xxxhdpi"케이스에서만 작동한다는 것을 알고 있습니다. 나중에이 스크립트에 나머지 접미사를 적용 할 다른 사례가 있기를 바랍니다 (영어가 나쁘면 죄송합니다).
스크립트 자체는 이름 변경 및 이동에 잘 작동합니다. 하지만 함께 일하게 할 수는 없습니다.
현재 문제는 다음 두 줄에 있습니다.
set name of this_item to my replace(theName, theSource, theReplacement)
move this_item to folder "xxxhdpi" of folder assetsFolder
파일 이름이 변경되었지만 이동에 실패했거나 파일이 이동되었지만 이름을 바꾸지 못했습니다.
또한이 작업 (안드로이드 자산 구성)을 수행하기 위해 플러그인을 검색하려고 시도했지만 운이 없었습니다. 이 applescript 작성에 대한 도움을 얻었거나 누군가가 작업을 수행하는 동등한 플러그인을 알려줄 것입니다.
미리 감사드립니다
이를 시도하면 스크립트는 하위 폴더의 이름이 항상 (마지막) 하이픈과 이름 확장명 앞의 점 사이의 부분이고 파일 이름에 항상 하나 이상의 하이픈이 있다고 가정합니다.
스크립트는 ditto
즉시 중간 디렉토리를 생성 할 수 있는 명령 줄 인터페이스 를 사용합니다 . 선택한 각 파일의 이름과 확장자를 분리하고 파일 이름에서 하위 폴더 이름을 제거합니다. "수동으로"하위 폴더를 만들 필요는 없습니다.
tell application "Finder"
set selectedItems to selection
if selectedItems is {} then return
set parentFolder to POSIX path of (container of item 1 of selectedItems as text)
end tell
set {TID, text item delimiters} to {text item delimiters, "-"}
repeat with anItem in selectedItems
set {fileName, fileExtension} to splitNameExtension(anItem)
tell text items of fileName to set {prefix, suffix} to {items 1 thru -2 as text, item -1}
set newFilePath to quoted form of (parentFolder & suffix & "/" & prefix & fileExtension)
set sourceFile to quoted form of POSIX path of (anItem as text)
do shell script "/usr/bin/ditto " & sourceFile & space & newFilePath & "; /bin/rm " & sourceFile
end repeat
set text item delimiters to TID
on splitNameExtension(aFile)
set {name:fileName, name extension:fileExtension} to aFile
if fileExtension is missing value then return {fileName, ""}
return {text 1 thru ((count fileName) - (count fileExtension) - 1) of fileName, "." & fileExtension}
end splitNameExtension
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다