defrun_applescript(script): """运行 AppleScript 脚本""" subprocess.run(["osascript", "-e", script]) defxls_to_xlsx(file_path="./xxx.xls"): """使用 AppleScript 修改 Excel 文件元数据""" applescript = f''' tell application "Microsoft Excel" -- 打开 .xls 文件 set inputFile to "{file_path}" -- 修改为你的文件路径 open inputFile -- 获取当前工作簿 set wb to active workbook -- 定义输出文件路径 set outputFile to "{file_path}x" -- 修改为你想保存的文件路径 -- 保存为 .xlsx 格式 save workbook as wb filename outputFile file format Excel XML file format -- 关闭工作簿 close wb saving no end tell ''' run_applescript(applescript)
defxlsx_to_xls(file_path="./xxx_tmp.xlsx"): """使用 AppleScript 修改 Excel 文件元数据""" applescript = f''' tell application "Microsoft Excel" -- 打开 .xls 文件 set inputFile to "{file_path}" -- 修改为你的文件路径 open inputFile -- 获取当前工作簿 set wb to active workbook -- 定义输出文件路径 set xlsFilePath to (inputFile as text) set xlsFilePath to text 1 thru -6 of xlsFilePath -- 去掉 ".xlsx" set xlsFilePath to xlsFilePath & ".xls" # log xlsFilePath -- 保存为 .xls 格式 save wb in xlsFilePath # save workbook as wb filename xlsFilePath file format Excel98to2004 file format with overwrite -- 关闭工作簿 close wb saving yes end tell ''' run_applescript(applescript)
defswrr_n(rs_arr, weight_total, schedule_num): ms = [(rs["ew"] / float(weight_total)) * (schedule_num-1) for rs in rs_arr] mzs = [int(m) for m in ms] mxs = [(i, m-int(m)) for i, m inenumerate(ms)] mxs = sorted(mxs, key=lambda x:x[1], reverse=True) for i, rs inenumerate(rs_arr): rs["cw"] = schedule_num * rs["ew"] rs["cw"] -= mzs[i] * weight_total
d = (schedule_num-1) - sum(mzs) for i inrange(d): rs_arr[mxs[i][0]]["cw"] -= weight_total
#!/bin/bash # Author: Matt Mastracci (matthew@mastracci.com) # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script # licensed under cc-wiki with attribution required # Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm if [[ $NAME = "iTerm" ]]; then FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` else FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose folder with prompt "Choose a folder to place received files in"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` fi
if [[ $FILE = "" ]]; then echo Cancelled. # Send ZModem cancel echo -e \\x18\\x18\\x18\\x18\\x18 sleep 1 echo echo \# Cancelled transfer else cd"$FILE" /usr/local/bin/rz -E -e -b sleep 1 echo echo echo \# Sent \-\> $FILE fi
#!/bin/bash # Author: Matt Mastracci (matthew@mastracci.com) # AppleScript from http://stackoverflow.com/questions/4309087/cancel-button-on-osascript-in-a-bash-script # licensed under cc-wiki with attribution required # Remainder of script public domain
osascript -e 'tell application "iTerm2" to version' > /dev/null 2>&1 && NAME=iTerm2 || NAME=iTerm if [[ $NAME = "iTerm" ]]; then FILE=`osascript -e 'tell application "iTerm" to activate' -e 'tell application "iTerm" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` else FILE=`osascript -e 'tell application "iTerm2" to activate' -e 'tell application "iTerm2" to set thefile to choose file with prompt "Choose a file to send"' -e "do shell script (\"echo \"&(quoted form of POSIX path of thefile as Unicode text)&\"\")"` fi if [[ $FILE = "" ]]; then echo Cancelled. # Send ZModem cancel echo -e \\x18\\x18\\x18\\x18\\x18 sleep 1 echo echo \# Cancelled transfer else /usr/local/bin/sz "$FILE" -e -b sleep 1 echo echo \# Received $FILE fi