2014-12-16 9 views
1

사파리 창에 키 입력을 입력하는 간단한 봇을 만들려고합니다. 이것은 데이터 입력 및 뷰 - 부스팅 등을 위해 유용 할 것이다. 저는 똑같은 일련의 키 스트로크를 하루에 수천 번 웹 양식으로 입력해야한다는 뇌사 상태의 직업을 가지고 있습니다. 나는 이것을 자동화하고 싶다. Applescript : Safari의 키 입력 루프 자동화

내가 스크립트 창을 활성화하고 전면에 탭 하나를 가져올 것이다


activate application "Safari" 
tell front window of application "Safari" to set current tab to tab 1 
repeat 1000 times 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke " " 
    delay (15) 
    tell application "Safari" to keystroke "SPACE" 
    delay (70) 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "SPACE" 
    delay (15) 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "TAB" 
    tell application "Safari" to keystroke "SPACE" 
end repeat 

현재 애플 스크립트에서 사용하고있는 스크립트이지만, 다음 중 하나를 개방 시작 새로운 즐겨 찾기 탭, 다른 코드를 인쇄하려고 ...

나는 스크립트가 실제로 T - A - B를 반복적으로 타이핑하고 있다고 믿기 때문에 시스템에 'TAB'을 누르는 방법에 문제가 있다고 생각합니다. .

내가 할 스크립트를 필요로하는 것입니다 : Tab 키를 12 번 15 초 동안 를 눌러 SPACE 번 15 초 동안 대기 를 눌러 SPACE 번 70초 Tab 키를 네 번에 대기 를 눌러 SPACE 번 기다립니다 Tab 키를 세 번 를 눌러 SPACE는

반복 약 1 000 회 ...

새로운 코드 내 스크립트 또는 제안에 대한 모든 수정이 될 것입니다 ppreciated.

+0

당신은 또한 [셀레늄] (http://docs.seleniumhq.org/)의 관심으로 전용 브라우저 자동화 도구를 찾을 수 있습니다. (또는 crikey, 당신이 할 수 있다면 가능하다면 그 사람이 영혼을 파괴하는 것 같아서 더 좋은 직업을 찾으십시오.) – foo

답변

1

글쎄, 여기 실제 코드를 통해 시작할 수 있습니다. 키 입력은 앱 "시스템 이벤트"의 명령입니다. 일부 반복을 사용하여 스크립트를 단순화 할 수 있으며 사이트에 따라 일부 탭 사이에 '지연 .2'를 추가해야 할 수 있습니다.

tell application "Safari" to activate 
delay 1 
tell front window of application "Safari" to set current tab to tab 1 
tell application "System Events" 
    tell process "Safari" 
     repeat 10 times 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke " " 
      delay (15) 
      keystroke " " 
      delay (70) 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke " " 
      delay (15) 
      keystroke tab 
      keystroke tab 
      keystroke tab 
      keystroke " " 
     end repeat 
    end tell 
end tell 

학술적 목적으로 만 반복을 추가하려면 실제로 말 블록을 반복하지 마십시오. 내가 좋아하는 뭔가를 할 거라고 :

tell application "System Events" 
    tell process "Safari" 
     repeat 1000 times 
      repeat 12 times 
       keystroke tab 
      end repeat 
      keystroke " " 
      delay (15) 
      keystroke " " 
      delay (70) 
      repeat 4 times 
       keystroke tab 
      end repeat 
      keystroke " " 
      delay (15) 
      repeat 3 times 
       keystroke tab 
      end repeat 
      keystroke " " 
     end repeat 
    end tell 
end tell 

그러나 다시, 문제 해결, 어떤 장소가 아니라 모두가 더 지연, 그것을 통합에 대한 그래서 진짜 이득을 필요가있을 수 있습니다.

+0

정말 고마워요 - jweaks : 멋진 제안. 나는 그 일을하는 법을 알지 못했지만 그것을 찾았으며 지금 할 수 있습니다! –

+0

고맙습니다. adayzdone : 저는 새로운 트릭을 배우기를 희망했기 때문에 TypeIt (스크립트가 내 작업을 수행하는 동안)을 가지고 놀고 있습니다. –

1

반복되는 명령에 대해서는 처리기를 사용해야합니다.

tell application "Safari" 
    activate 
    tell front window to set current tab to tab 1 
end tell 

repeat 10 times 
    typeIt(tab, 12) 
    typeIt(space, 1) 
    delay 15 
    typeIt(space, 1) 
    delay 70 
    typeIt(tab, 4) 
    typeIt(space, 1) 
    delay 15 
    typeIt(tab, 3) 
    typeIt(space, 1) 
end repeat 

on typeIt(stroke, n) 
    tell application "System Events" 
     tell process "Safari" 
      repeat n times 
       keystroke stroke 
       delay 0.2 
      end repeat 
     end tell 
    end tell 
end typeIt