2013-02-19 2 views
1

FoldingText 윤곽선 (기본적으로 Markdown 텍스트 파일)을 Remark 프리젠 테이션 (Markdown 파일의 슬라이드 쇼를 만드는 HTML 스크립트)으로 변환하는 FoldingText에 대해 script에서 작업하고 있습니다.). 스크립트는 작동하지만 다음과 같이 개선하고 싶습니다.현재 문서를 같은 이름과 경로로 .html로 저장합니다.

HTML 파일을 저장할 이름과 위치를 묻는 대신 현재 문서의 이름을 가져 와서 저장하고 싶습니다. 현재 폴더에 같은 이름의 HTML 파일이 있습니다. 이 이름을 가진 문서가 이미 있으면 스크립트가 제대로 실패합니다 (문서를 덮어 쓰거나 다른 이름으로 새 문서로 저장할 수 있음).

파일에 쓰는 데 사용하는 스크립트는이 포럼에서 가져온 것입니다.

on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean) 
try 
    set the target_file to the target_file as text 
    set the open_target_file to ¬ 
     open for access file target_file with write permission 
    if append_data is false then ¬ 
     set eof of the open_target_file to 0 
    write this_data to the open_target_file starting at eof as «class utf8» 
    close access the open_target_file 
    return true 
on error 
    try 
     close access file target_file 
    end try 
    return false 
end try 
end write_to_file 

그리고 두 번째 부분은 다음과 같습니다 : 첫 번째 부분은

set theFile to choose file name with prompt "Set file name and location:" 
my write_to_file(finalText, theFile, true) 

감사합니다.

답변

0

FoldingText에는 문서의 경로를 검색 할 수있는 방법이 있어야합니다. 응용 프로그램에 대한 무료 dowonload를 찾지 못했기 때문에 직접 확인하지는 못했지만 응용 프로그램 사전을 보면 찾을 수 있습니다.

내 생각은 FoldingText의 문서 '의 파일'이 속성이 '경로'처럼, 또는이다 :

당신은 아마 이런 일에 종료됩니다 :에

set theDocPath to file of front document of application "FoldingText" 
tell application "Finder" 
set theContainer to container of theFile 
end tell 
set newPath to (theContainer & "export.html) as string 
repeat while (file newPath exists) 
set newPath to choose file name with prompt "Set file name and location:" 
end repeat 

my write_to_file(finalText, newPath, true) 
+0

주셔서 감사합니다 내가 찾던 것과 가까운 것을 얻을 수있게 도와주세요. 현재 오류 처리가 없으며 단순히 전체 파일 이름에 HTML을 추가합니다. 더 나은 스크립트는 파일이 존재하는 경우 "다른 이름으로 저장"을 수행하고 .html을 추가하기 전에 기존 .md, .txt 또는 .ft 확장자를 제거합니다. 하지만 지금은 괜찮습니다. 는' 내 write_to_file에게 ((문자열로 thedocument) ".html 중에서") 끝에 세트 newpath를 "FoldingText"응용 프로그램 앞에 문서의 파일로 전면 응용 프로그램의 문서 "FoldingText" 설정 thedocument에게 (finalText, newpath를 , true)' – Kerim

+0

흠. 그것은 내가 원하는 방식으로 코드를 포맷하게하지 않을 것이고, 5 분 후에 더 이상 편집 할 수 없다고 말했다. 다음은 개정 된 스크립트에 대한 [link] (http://support.foldingtext.com/discussions/questions/357-script-to-generate-remark-formatted-html-file-form-foldingtext#comment_25496591)입니다. – Kerim

+0

참고 :이 파일을 두 번 실행하면 기존 파일을 덮어 쓰지 않고이 스크립트가 추가되어 문제가 발생합니다. 어떻게 든 그것을 피할 필요가 있습니다. – Kerim

관련 문제