Shell 将windows.bat重写为AppleScript或UNIX
我试图重写一些代码,但是脚本语言对我来说太奇怪了。。。有人能帮我重写一下吗?我甚至无法从当前文件路径获取当前文件夹路径。。。这是windows.bat,我想在我的Mac上运行它。 谢谢Shell 将windows.bat重写为AppleScript或UNIX,shell,unix,applescript,Shell,Unix,Applescript,我试图重写一些代码,但是脚本语言对我来说太奇怪了。。。有人能帮我重写一下吗?我甚至无法从当前文件路径获取当前文件夹路径。。。这是windows.bat,我想在我的Mac上运行它。 谢谢 因此,这与脚本语言本身无关,因为脚本中唯一使用脚本语言的部分是for循环。您可能可以用find-depth 1命令替换它,但是bash中的for循环如下所示: for i in myFolder/*; do #blah #blah done 您真正需要了解的是如何替换bash脚本中的mkdir和xcop
因此,这与脚本语言本身无关,因为脚本中唯一使用脚本语言的部分是
for
循环。您可能可以用find-depth 1
命令替换它,但是bash中的for
循环如下所示:
for i in myFolder/*; do
#blah
#blah
done
您真正需要了解的是如何替换bash脚本中的mkdir
和xcopy
等功能。为此,您需要了解在此脚本中使用的各种标志的作用,以及如何在选项中模拟它们的行为,例如,mkdir
、cp
和rm
我自己做的
on run
display dialog "Wait for the end"
set CURRENT_DIR to POSIX path of (do shell script "dirname " & POSIX path of ((path to me) as Unicode text)) & "/" as string
set CONVERT_UTIL to "java -cp . transform student.xsl"
set DST_CVICENIA to CURRENT_DIR & "web"
set CVICENIA to CURRENT_DIR & "cvicenia"
tell application "Finder"
try
delete folder (DST_CVICENIA as POSIX file)
end try
make new folder at (CURRENT_DIR as POSIX file) with properties {name:"web"}
copy folder (CURRENT_DIR & "/style" as POSIX file) to folder (DST_CVICENIA as POSIX file)
set CVICENIA_LIST to get name of folders of folder (CVICENIA as POSIX file)
repeat with I in CVICENIA_LIST
make new folder at (DST_CVICENIA as POSIX file) with properties {name:I}
set DST_CVICENIA_I to DST_CVICENIA & "/" & I
set CVICENIA_I to CVICENIA & "/" & I
copy items of folder (CVICENIA_I as POSIX file) to folder (DST_CVICENIA_I as POSIX file)
do shell script "cd " & CURRENT_DIR & "\n" & CONVERT_UTIL & " " & CVICENIA_I & "/index.xml " & DST_CVICENIA_I & "/index.html"
delete item (DST_CVICENIA_I & "/index.xml" as POSIX file)
end repeat
end tell
display dialog "End"
end run
接受你自己的答案,这样问题就会得到回答。
on run
display dialog "Wait for the end"
set CURRENT_DIR to POSIX path of (do shell script "dirname " & POSIX path of ((path to me) as Unicode text)) & "/" as string
set CONVERT_UTIL to "java -cp . transform student.xsl"
set DST_CVICENIA to CURRENT_DIR & "web"
set CVICENIA to CURRENT_DIR & "cvicenia"
tell application "Finder"
try
delete folder (DST_CVICENIA as POSIX file)
end try
make new folder at (CURRENT_DIR as POSIX file) with properties {name:"web"}
copy folder (CURRENT_DIR & "/style" as POSIX file) to folder (DST_CVICENIA as POSIX file)
set CVICENIA_LIST to get name of folders of folder (CVICENIA as POSIX file)
repeat with I in CVICENIA_LIST
make new folder at (DST_CVICENIA as POSIX file) with properties {name:I}
set DST_CVICENIA_I to DST_CVICENIA & "/" & I
set CVICENIA_I to CVICENIA & "/" & I
copy items of folder (CVICENIA_I as POSIX file) to folder (DST_CVICENIA_I as POSIX file)
do shell script "cd " & CURRENT_DIR & "\n" & CONVERT_UTIL & " " & CVICENIA_I & "/index.xml " & DST_CVICENIA_I & "/index.html"
delete item (DST_CVICENIA_I & "/index.xml" as POSIX file)
end repeat
end tell
display dialog "End"
end run