2017-02-18 3 views
0

변수 값을 사용하여 AppleScript에서 함수/서브 루틴을 호출하려면 어떻게해야합니까? 여기에 변수가 "뭔가"를 이름 대신, 내가 (대신 호출 시도 "뭔가"기능)AppleScript에서 함수/서브 루틴 호출에 변수 값 사용

on HelloWorld() 
    display alert "Hello world." 
end HelloWorld 

set something to "HelloWorld" 

something() 

나는 그것이하여 HelloWorld (변수 값)를 호출 할을 수행 할 작업의 예입니다.

이 스크립트 객체의 핸들러를 포장하고 검색 목록에 넣어하는 것입니다 할

답변

0

올바른 방법 :

-- define one or more script objects, each with a custom `doIt()` handler 

script HelloWorld 
    to doIt() 
     display alert "Hello world." 
    end doIt 
end script 

script GoodnightSky 
    to doIt() 
     say "Goodnight sky." 
    end doIt 
end script 


-- put all the script objects in a list, and define a handler 
-- for looking up a script object by name 

property _namedObjects : {HelloWorld, GoodnightSky} 

to objectForName(objectName) 
    repeat with objectRef in _namedObjects 
     if objectName is objectRef's name then return objectRef's contents 
    end repeat 
    error "Can't find object." number -1728 from objectName 
end objectForName 


-- look up an object by name and send it a `doIt()` command 

set something to "HelloWorld" 
objectForName(something)'s doIt() -- displays "Hello world" 

set something to "GoodnightSky" 
objectForName(something)'s doIt() -- says "Goodnight sky"