diff --git a/osagetlang.sh b/osagetlang.sh index f82c09a..44e0d63 100755 --- a/osagetlang.sh +++ b/osagetlang.sh @@ -1,6 +1,7 @@ #!/usr/bin/env osascript use AppleScript version "2.4" +use scripting additions use framework "Foundation" use framework "OSAKit" @@ -9,7 +10,15 @@ on run args set scpt_path to item 1 of args set source_nsurl to current application's NSURL's fileURLWithPath:scpt_path set the_script to current application's OSAScript's alloc()'s initWithContentsOfURL:source_nsurl |error|:(missing value) - if the_script is missing value then error "File or contained script is unreachable" number 1 + if the_script is missing value then error "Script cannot be loaded by OSAScript" number 2 set osa_lang to the_script's language()'s |name| as text + if osa_lang is "AppleScript" then + #verify if it's really AppleScript (OSAScript thinks even a JPEG is an AppleScript file) + set cmd to "file --brief " & quoted form of scpt_path + set magic_file_type to do shell script cmd + if magic_file_type is not "AppleScript compiled" then + error "File is not an OSA script file (magic says: " & magic_file_type & ")" number 3 + end if + end if get osa_lang end run diff --git a/test-files/no-as.scpt b/test-files/no-as.scpt new file mode 100644 index 0000000..4af3705 --- /dev/null +++ b/test-files/no-as.scpt @@ -0,0 +1 @@ +This is a text-file, NOT an AppleScript file. diff --git a/test.sh b/test.sh index 3a915b2..8b534ab 100755 --- a/test.sh +++ b/test.sh @@ -138,6 +138,7 @@ lang_test "asdbg.scpt" "AppleScript Debugger" 0 "Get language of an AppleScript lang_test "js.scpt" "JavaScript" 0 "Get language of an JavaScript file" lang_test "perl.scpt" "Perl" 1 "Get language of non-existing file" lang_test "" "" 1 "Get language without arguments" +lang_test "no-as.scpt" "" 1 "Get language of a non-AppleScript file" #--| Instrumentarium to generate a test-error. if (( TEST_ERROR == 1 )); then