简体   繁体   中英

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. 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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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