2013-11-04 1 views
3

내 시스템이 부팅 될 때 세 가지 다른 데스크탑/공간에서 파일을 여는 applescript를 실행하고 싶습니다.applescript에서 파일을 열 때 어떤 바탕 화면을 지정할 수 있습니까?

First Space: Mail and Things (my to do list program) 
Second Space: Textmate and a Safari for my first project 
Third Space: Textmate and a Safari for my second project 

먼저 Mission Control에서 다음에 수동으로 제거하지 않는 한 시스템이 부팅 될 때 그곳에 남을 두 개의 데스크톱을 추가로 만들었습니다. 하나의 긴 스크립트를 만드는 대신 세 개의 applescript (boot1, boot2 및 boot3)를 묶어 간단한 코드 블록으로 분리했습니다. boot2에서

run script file "<drive name>:Users:<username>:boot2.scpt" 

을하고 delay 라인의 무리를 볼 수 boot3 : boot1의 끝에서 당신은 볼 수 있습니다. AppleScript에 대해 싫어하는 점 중 하나는 OS가 이전 명령에 응답하기 전에 다음 명령을 처리하기 시작하는 경우가 많다는 것입니다. 이로 인해 불일치와 오류가 발생합니다. 지연은 일이 천천히 진행되도록하는 해킹입니다. 그것들은 도움이됩니다, 그러나 당신이 그들을 사용할 때조차도 조금은 여전히 ​​위험합니다. boot2.script에서 :

# this emulates the keyboard shortcut to move to desktop 2 
# there doesn't seem to be any way to modify an `open` command to open a file on desktop 2 
tell application "System Events" 
    delay 2 
    # key code 19 is the key code for the number 2. 
    # <cntl> 2 is the shortcut to get to desktop 2 
    key code 19 using control down 
end tell 

tell application "TextMate" 
    activate 
    # 'sites' is the name of the directory my projects are in 
    open "https://stackoverflow.com/users/<username>/sites/project1/" 
end tell 

tell application "Terminal" 
    activate 
    do script "cd /users/<username>/sites/project1/" 

    delay 2 
    do script "rails s" in front window 

    delay 2 
    tell application "System Events" to tell process "Terminal" to keystroke "t" using command down 
    tell application "System Events" to tell process "Terminal" to keystroke return 

    delay 2 
    do shell script "open -a Safari http://localhost:3000" 
end tell 

OK ... 그래서 이것은 대부분 지연 길이가 충분하지 않을 때 불일치를 제외하고 대신 바탕 화면 (2)를 얻을 작동합니다. Boot3.script는 boot2와 거의 같지만 데스크톱 3에서 응용 프로그램을 열려고하면 바탕 화면 2에 창이 있으므로 해당 시스템으로 돌아갑니다. 이것은 다음 문제입니다. 어떻게 극복합니까?

2305491은 공간 환경 설정이 없어져 더 이상 적합하지 않습니다.

감사합니다.

+1

같은 것입니다. autmator 녹음 기능을 사용할 수 있습니다. – idmean

답변

1

Boot3.script는 boot2와 거의 동일하지만 데스크톱 3에서 응용 프로그램을 열려고하면 바탕 화면 2에 창이 있기 때문에 시스템이 해당 바탕 화면으로 다시 이동합니다.

미션 컨트롤 환경 설정에 "응용 프로그램으로 전환 할 때 응용 프로그램의 열린 창으로 전환"이라는 옵션이 있습니다. 선택을 취소하십시오.

OK ... 이것은 대부분 지연이 충분하지 않을 때 불일치를 제외하고 데스크톱 2를 제자리에 유지하기 위해 작동합니다.

더 나은 솔루션은 항상 내가 AppleScript를 사용하여이 작업을 수행하는 이유는 더 있다고 생각하지 않습니다이

repeat until something exists 
delay 0.1 
end repeat 
관련 문제