Preventing users from editing the dialog
You can, to some extent, prevent users from editing your dialog. There is no absolute protection, though: expert users will easily edit your dialog anyhow.
-
You can trap the menu event which toggles the dialog into edit mode. This is the Edit menu command. Insert in the script of the dialog the following handler:
on do menu the_cmd to the_dialog
if the_cmd is "Edit" then return
continue do menu the_cmd to the_dialog
end do menu
-
You can delete the Edit ▸ Edit mode ⌘Y menu item. You would do so in the prepare handler of the script of the dialog:
on prepare the_dialog
set n to count menu item of menu "Edit"
set visible of menu item (n-1) of menu "Edit" to false -- separator line
set visible of menu item n of menu "Edit" to false -- "Edit mode"
[...]
This is reversible, a script can show the menu items back.
In both cases, the user can still toggle the dialog into edit mode by script:
set the_dialog to window 2
set mode of the_dialog to true -- into edit mode
set mode of the_dialog to false -- into normal mode
The user can also still edit the script of the dialog by script:
EditObjectScript(the_dialog)
Preventing users from editing the script of the dialog
You can prevent users from editing the script of your dialog. This is robust: the user may be able to break the dialog, not to view the source of your script. The mechanism consists in storing a separate script saved as run-only, and "manually" loading that script into the dialog.
-
Make your dialog normally.
-
Once your dialog final, save the dialog's script into two files: one that you will keep for future use, and one that you save as a run-only script.
-
By script, set the dialog's script to the run-only script:
set the_script to load script (the_run_only_alias)
set script of the_dialog to the_script
save the_dialog in 0
The script of the dialog is now non-editable. To make it editable again you must first set it by script to some editable script:
set script of the_dialog to "property whatever:0"
then you can edit it again (but still you will not recover the run-only script's source, you must use your backup copy).
|