2017-05-17 21 views
1

프론트 엔드 응용 프로그램 x가 무엇인지 알아 내려고 스크립트를 실행 한 다음 x를 applescript를 사용하여 프론트 엔드 응용 프로그램으로 설정하려고합니다. 이 코드는 버그를 반환하지 않지만applescript에서 프론트 엔드에 응용 프로그램을 설정합니다.

tell application "System Events" 
set frontApp to displayed name of first process whose frontmost is true 
set apptemp to frontApp 
end tell 

[코드 여기]

tell application "System Events" 
set frontmost of process whose name is apptemp to true 
end tell 

은 작동하지 않습니다. 또한이 코드를 시도했습니다.

tell application "System Events" 
set apptemp to application "Google Chrome" 
set frontmost of process "Google Chrome" to true 
end tell 

그러나 버그는 없지만 작동하지 않습니다.

또한 관리자에게 코드를 쉽게 표시하도록 알려 주시기 바랍니다. 나는이 웹 사이트에 코드를 표시하는 데 가장 힘든 시간을 보냈습니다. 각 코드 줄마다 네 칸을 들여 쓰기해야하는데, 그건 제정신이 아닙니다. 에 관계없이 중복 및 그 과정 이름이 다른 응용 프로그램으로, 응용 프로그램의 특정 경로를 사용

# Save which application is frontmost (active), 
# as an absolute, HFS-style path string pointing to the application bundle. 
set frontmostAppPath to (path to frontmost application) as text 

# Activate and work with another application. 
activate application "Reminders" 
delay 2 

# Make the previously frontmost (active) application frontmost again. 
activate application frontmostAppPath 

가 매우 동일한 응용 프로그램이 활성화되는 것을 보장 :

+1

도움말에서 코드 들여 쓰기에 대해 : * 텍스트를 선택하고 CTRL + K를 눌러 들여 쓰기를 코드 *로 토글 할 수도 있습니다. – vadian

+0

그들은 웹 페이지에서 더 명확하게해야합니다. – bobsmith76

+0

새 이민자에게 표준 조언을 해 줄 수 있습니다 : 답변으로 문제가 해결되면 그 옆에있는 큰 체크 표시 (✓)를 클릭하고 선택 사항으로 투표하십시오 (up-vote를 사용하려면 15 가지 이상의 평판이 필요합니다) 전철기). 다른 답변이 도움이된다면 위로 투표하십시오. 수락 (2 가지 평판 포인트를 얻을 수 있음) 및 up-voting은 미래의 독자에게 도움이됩니다. 관련 도움말 센터 문서 (http://stackoverflow.com/help/someone-answers)를 참조하십시오. 귀하의 질문에 아직 완전히 대답하지 않은 경우, 피드백이나 [self-answer] (http://stackoverflow.com/help/self-answer)를 제공해주십시오. – mklement0

답변

1

이 처리하는 강력한 방법은 다음과 같이 path to frontmost application을 사용하는 것입니다.

참고 : 저장하고 객체 참조 frontmost application직접을 복원하려는 유혹하지만 실제로는 작동하지 않습니다 알수없는, 그런 저장된 참조가 현재 응용 프로그램과 같은 처리됩니다 (하나 개의 실행 코드).

1

다른 두 가지 방법보다 훨씬 더 나은 것은 고유 키인 번들 식별자를 사용하는 것입니다.

tell application "System Events" 
    set frontAppID to bundle identifier of first process whose frontmost is true 
end tell 

-- Sample code... can be anything else 
activate application "Finder" 
delay 3 
-- End of sample code 

activate application id frontAppID 
+0

'id of application (텍스트를 가장 앞쪽에있는 애플리케이션으로의 경로)'로 단축 할 수는 있지만, 그렇다고하더라도 고유 한 경로를 사용하는 것보다 더 나은 방법은 없습니다. 당신은 접근하는 방법을 언급합니다 - 다른 것은 무엇입니까? – mklement0