简体   繁体   English

使脚本在OSX上可执行?

[英]Make script executable on OSX?

I wrote a little script in python, it basically open a VPN program and then it open a new window in firefox and log in a website. 我用python写了一个小脚本,它基本上打开了一个VPN程序,然后在firefox中打开了一个新窗口并登录了网站。 I would like now to avoid launching it from the terminal, and be able to make double click on it(is it called an executable file?). 我现在想避免从终端启动它,并且能够双击它(它称为可执行文件吗?)。 How can I achieve this? 我该如何实现? I work with python 2.7 on a mac 10.11.1. 我在Mac 10.11.1。上使用python 2.7。

I am sorry for eventual mistake but programming is still quite new for me! 对于最终的错误,我感到很抱歉,但是编程对我来说还是很新的!

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

You can use Automator to wrap a Python script to a normal Mac App bundle that can be opened from OSX GUI. 您可以使用Automator将Python脚本包装到可以从OSX GUI打开的普通Mac App捆绑包中。

Better still, what you are trying to achieve can be probably better implemented as set of action in Automator without having to write any Python scripts. 更好的是,您可以尝试将要实现的目标更好地实现为Automator中的一组操作,而无需编写任何Python脚本。

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

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