사과 스크립트 응용 프로그램 파일에서 읽습니다
-
07-07-2019 - |
문제
Windows 서버로 이동 한 컴파일 된 AppleScript 응용 프로그램이 있습니다. 그런 다음 응용 프로그램에 텍스트 파일을 삽입하고 싶습니다 (Windows의 zip 파일처럼 보임) :
myapplescript.app/Contents/Resources/MyNewDir/MyTxtFile.txt
그래서 나는이 텍스트 파일에서 읽고 내용을 문자열로 가져 오려고 AppleScript를 사전 컴파일했습니다. 이것이 제가하는 것입니다:
set theFolder to POSIX path of (the path to me)
set theFile to theFolder & "Contents/Resources/MyNewDir/MyTxtFile.txt"
open for access theFile
set fileContents to (read theFile)
close access theFile
그러나 이것은 내가 얻는 오류입니다.
"/users/mike/desktop/myapplescript.app/contents/resources/mynewdir/mytxtfile.txt"를 유형 파일로 만들 수 없습니다
해결책
좋아, 나는 그것을 알아 냈다. 나는 두 번째 줄을 이것으로 바꿨다 :
set theFile to (POSIX file (theFolder & "Contents/Resources/MyNewDir/MyTxtFile.txt"))
다른 팁
읽기의 단일 줄 버전도 있습니다.
read POSIX file "/tmp/test.txt" as «class utf8»
두 버전 모두 추가하지 않는 한 MacRoman을 사용합니다 as «class utf8»
. (as Unicode text
UTF-16입니다.)
변수의 파일 경로를 통해 파일을 읽습니다.
첫 번째 두 작업. 파일 이름을 변수에 저장하는 세 번째는 그렇지 않습니다.
MyData를 파일 POSIX 파일을 읽도록 설정하십시오 ¬ "/users/sww/devel/afile.csv"
MyData를 파일을 읽도록 설정 ¬ "Macintosh HD : 사용자 : SWW : Devel : afile.csv"
set fRef to "Macintosh HD:Users:sww:Devel:afile.csv"
set myData to read file fRef -- No good
고치다? 파일 참조를 문자열로 제공하십시오.
set myData to read file (fRef as string) -- OK
제휴하지 않습니다 StackOverflow