繁体   English   中英

使脚本在OSX上可执行?

[英]Make script executable on OSX?

我用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

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

更好的是,您可以尝试将要实现的目标更好地实现为Automator中的一组操作,而无需编写任何Python脚本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM