دليل مرجعي سريع لكتابة وتشغيل كود AppleScript على نظام macOS، بدءاً من أوامر osascript في الطرفية وحتى أتمتة واجهة المستخدم.
تشغيل AppleScript
من سطر الأوامر (osascript)
# تنفيذ تعبير فوري مباشر
osascript -e 'display notification "Task completed!" with title "Build Script"'
# تشغيل ملف سكربت (.scpt أو .applescript)
osascript script.scpt
إشعارات النظام الأصلية
display notification "Backup finished successfully" with title "System Status" subtitle "Automated Backup"
التعليقات
-- هذا تعليق سطر واحد
# هذا أيضاً تعليق سطر واحد
(*
هذا تعليق
متعدد الأسطر
*)
الصوت والإشارات الصوتية
تركيب ونطق الكلام (say)
-- الصوت الافتراضي للنظام
say "Build succeeded"
-- صوت محدد من أصوات النظام
say "Warning: low battery" using "Zarvox"
say "All systems nominal" using "Samantha"
صافرة تنبيه النظام (Beep)
-- صوت تنبيه لمرة واحدة
beep
-- صوت تنبيه لعدة مرات
beep 3
تأخير التنفيذ (Delay)
-- إيقاف التنفيذ مؤقتاً لمدة 5 ثوانٍ
delay 5
المعالجات (الدوال / Handlers)
on doubleNumber(n)
return n * 2
end doubleNumber
set doubledValue to my doubleNumber(21)
-- → 42
معالج بوسائط متعددة
on showDialog(msg, titleText)
display alert titleText message msg as informational
end showDialog
my showDialog("Operation completed.", "Success")
التفاعل مع تطبيقات macOS
tell application "Finder"
activate
open folder "Documents" of home
end tell
tell application "Google Chrome"
reload active tab of front window
end tell