
Applescript for Advanced Users
applescript အေၾကာင္းပါ။ အသံုုးျပဳခ်င္တဲ့သူမ်ား အဆင္ေျပေစဖိုု႔ အသံုုးဝင္မယ့္ applescript ေတြကိုု ဒီ post ေအာက္မွာ တင္ေပးပါမယ္။
applescript ဆိုုတာ mac မွာ အရမ္း powerful ျဖစ္တဲ့ tool ပါ။ mac settings ေတြေတာ္ေတာ္မ်ားမ်ားကိုု one click run နဲ႔ ေျပာင္းလိုု႔ရပါတယ္။
Apple ကဖန္တီးထုုတ္လုုပ္ထားတဲ့ scripting language တစ္ခုုျဖစ္ပါတယ္။ applescript ကိုု ေရးဖိုု႔ mac မွာ AppleScript Editor ဆိုုတာထည့္ေပးထားပါတယ္။
example:
display dialog “Hello, world!”
ဒါထည့္ျပီး run ၾကည့္ပါ Cancel and Ok ပါတဲ့ dialog တစ္ခုုရမွာပါ။
display alert “Hello, world!”
ဒီတစ္ခုုကေတာ့ OK တစ္ခုုတည္းပါမယ့္ alert တစ္ခုုပါ။
say “Hello, world!”
ဒါကေတာ့ အသံထြက္ေပးမွာပါ။
ျပီးရင္ file ထဲက save မွာသိမ္းထားရံုုပါပဲ။ Distribute လုုပ္ခ်င္ရင္ေတာ့ file format ကိုု Application ေရြးျပီး save လုုပ္ပါ။
ေအာက္မွာ အသံုုးဝယ္မယ့္ script ေတြကိုု တင္ေပးပါမယ္။
ဒါထည့္ျပီး run ၾကည့္ပါ Cancel and Ok ပါတဲ့ dialog တစ္ခုုရမွာပါ။
ဒီတစ္ခုုကေတာ့ OK တစ္ခုုတည္းပါမယ့္ alert တစ္ခုုပါ။
ဒါကေတာ့ အသံထြက္ေပးမွာပါ။
ဒါက Mac မွာပါတဲ့ Myanmar Font ေတြကိုု disable လုုပ္ဖိုု႔ပါ။ အသံထြက္ေလးပါ ထည့္ျပီးစမ္းၾကည့္ပါ။
Sample 1. Disable MyanmarMN Font
———–
say “Welcome to MacMyanmar!”
tell application “Font Book”
activate
set myFonts to {“Myanmar MN”, “Myanmar MN Bold”, “Myanmar Sangam MN”}
set fontNames to name of typefaces
repeat with i from 1 to count myFonts
set fontName to item i of myFonts
try
set enabled of typeface fontName to false
end try
end repeat
end tell
Sample 1. Disable MyanmarMN Font
———–
say “Welcome to MacMyanmar!”
tell application “Font Book”
activate
set myFonts to {“Myanmar MN”, “Myanmar MN Bold”, “Myanmar Sangam MN”}
set fontNames to name of typefaces
repeat with i from 1 to count myFonts
set fontName to item i of myFonts
try
set enabled of typeface fontName to false
end try
end repeat
end tell
Sample 2. Enabled MyanmarMN Font
———–
———–
ဒါကေတာ့ ျပန္ျပီး enable လုုပ္ဖိုု႔ပါ။
tell application “Font Book”
activate
set myFonts to {“Myanmar MN”, “Myanmar MN Bold”, “Myanmar Sangam MN”}
set fontNames to name of typefaces
repeat with i from 1 to count myFonts
set fontName to item i of myFonts
try
set enabled of typeface fontName to true
end try
end repeat
end tell
Sample 3. Shutdown Now
ဒါ ထည့္ျပီး run လုုိက္လိုု႔ အေမးအျမန္းမရိွ shutdown လုုပ္သြားရင္ လာျပီး အျပစ္အေျပာၾကနဲ႕ file ထုုတ္ထားျပီး ခ်က္ခ်င္း shutdown လုုပ္ခ်င္တဲ့သူေတြအတြက္ သံုုးႏိုုင္ပါတယ္
on run
tell application “System Events” to shut down
end run
ဒါ ထည့္ျပီး run လုုိက္လိုု႔ အေမးအျမန္းမရိွ shutdown လုုပ္သြားရင္ လာျပီး အျပစ္အေျပာၾကနဲ႕ file ထုုတ္ထားျပီး ခ်က္ခ်င္း shutdown လုုပ္ခ်င္တဲ့သူေတြအတြက္ သံုုးႏိုုင္ပါတယ္
on run
tell application “System Events” to shut down
end run
Sample 4. QuitAllApp
ဒါကေတာ့ finder နဲ႔ AppleScript Editor ကလြဲလိုု႔ App အားလံုုးကိုု ပိတ္ေပးပါမယ္။ AppleScript Editor ပါပိတ္ခ်င္ရင္ေတာ့ စာတေၾကာင္းလံံုုးဖယ္ျပီး application အေနနဲ႔ save လုုပ္ျပီးမွာ စမး္ပါ။
– get list of open apps
tell application “System Events” to set theapps to name of every application process whose visible is true and name is not “Finder”
set keepapp to {“AppleScript Editor”}
– quit each app
repeat with closeapp in theapps
if closeapp is not in keepapp then quit application closeapp
end repeat
ဒါကေတာ့ finder နဲ႔ AppleScript Editor ကလြဲလိုု႔ App အားလံုုးကိုု ပိတ္ေပးပါမယ္။ AppleScript Editor ပါပိတ္ခ်င္ရင္ေတာ့ စာတေၾကာင္းလံံုုးဖယ္ျပီး application အေနနဲ႔ save လုုပ္ျပီးမွာ စမး္ပါ။
– get list of open apps
tell application “System Events” to set theapps to name of every application process whose visible is true and name is not “Finder”
set keepapp to {“AppleScript Editor”}
– quit each app
repeat with closeapp in theapps
if closeapp is not in keepapp then quit application closeapp
end repeat
Sample 5. empty trash
အမွိဳက္ေတြတခါထည္း သြန္လိုုက္မယ္။
tell application “Finder”
empty the trash
end tell
အမွိဳက္ေတြတခါထည္း သြန္လိုုက္မယ္။
tell application “Finder”
empty the trash
end tell
No comments:
Post a Comment