在OSX上使脚本可执行?

时间:2015-12-11 23:54:17

标签: python macos

我在python中写了一个小脚本,它基本上打开一个VPN程序,然后在firefox中打开一个新窗口并登录一个网站。我现在想避免从终端启动它,并能够双击它(它被称为可执行文件?)。我怎样才能做到这一点?我在mac 10.11.1上使用python 2.7。

对于最终的错误我很抱歉,但编程对我来说还是一个新的东西!

import webbrowser
from Quartz.CoreGraphics import *
import subprocess as sp
import time
import pyautogui

def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy),
kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);

# opening strong VPN
xfoil = sp.Popen(['open', '-a', '/Applications/StrongVPN Client.app'], stdin=sp.PIPE, stdout=sp.PIPE)

time.sleep(5)
mouseclick(900,360);
time.sleep(1)


#open firefox and going to skygo
b = webbrowser.get('firefox')
b.open('http://skygo.sky.it/index.shtml')

time.sleep( 5 )
mouseclick(1010,225);
#clicking on login;
mouseclick(1074,123);
time.sleep( 5 )
mouseclick(830,225);
time.sleep(2)
pyautogui.typewrite('myusername')
time.sleep(1)
#inserting  password
mouseclick(830,290);
time.sleep(2)
pyautogui.typewrite('mypassword')
time.sleep(1)
#pressing enter
mouseclick(920,400);
time.sleep(2)
#mousemove(int(currentpos.x),int(currentpos.y));  # Restore mouse position

1 个答案:

答案 0 :(得分:0)

您可以使用Automator将Python脚本包装到可以从OSX GUI打开的普通Mac App包中。

更好的是,您尝试实现的内容可能更好地实现为Automator中的一组操作,而无需编写任何Python脚本。