2012-05-29 2 views
0

하나의 AppleScript 파일에서 다른 변수로 전역 변수를 가져 오는 방법은 무엇입니까?AppleScript로 전역 변수 가져 오기

두 개의 AppleScript 파일을 사용하여 프로젝트 과정의 데모를 만듭니다.

한 애플 스크립트 파일 "main.scpt는"글로벌 변수이 파일에서 실행할 때 잘 작동

global someDirectory 
set someDirectory to "~/Documents/cs123-drj/demo" 

on openServerWindow() 
    # Open the server 
    tell application "System Events" to keystroke "n" using command down 
    tell application "System Events" to keystroke "i" using {command down, shift down} 
    typeKeys("server") 
    typeKeys(return) 
    tell application "System Events" to keystroke "i" using command down 
    typeKeys("cd ") 
    typeKeys(someDirectory) 
    typeKeys(return) 
    typeKeys("./cs123-server.sh") 
    typeKeys(return) 
end openServerWindow 

로 시작합니다. 이 파일을 라이브러리로 사용하고 싶습니다. 유행과 유사하게 발견 된 파일은 here입니다. 내 두 번째 AppleScript 전문은 다음과 같습니다.

# 
# Demo script for doing simultaneous selects from a CS123-DRJ database. 
# 

property CS123Commands : load script POSIX file "/Users/admin/Documents/cs123-drj/demo/main.scpt" 

tell CS123Commands to openServerWindow() 

이 코드를 실행하려고

, 내가받을 다음과 같은 오류 :

error "The variable someDirectory is not defined." number -2753 from "someDirectory"

가 어떻게 내 두 번째 애플 스크립트 파일에이 변수를 가져올 수 있습니다 ?

답변

2

로드 할 때 실제로 스크립트를 실행하지 않아 someDirectory가 설정되지 않습니다. 대신이 속성을 사용하여이 문제를 해결할 수 있습니다. 그래서 ...

global someDirectory 
set someDirectory to "~/Documents/cs123-drj/demo" 

에 ...

property someDirectory: "~/Documents/cs123-drj/demo" 
+0

완벽이를 변경! 내가 필요한 것. –