Skip to content

Commit

Permalink
Added magic test to osagetlang when it's an AppleScript file
Browse files Browse the repository at this point in the history
  • Loading branch information
doekman committed May 29, 2018
1 parent fa74d67 commit 6f4991b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion osagetlang.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env osascript

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "OSAKit"

Expand All @@ -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
1 change: 1 addition & 0 deletions test-files/no-as.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a text-file, NOT an AppleScript file.
1 change: 1 addition & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6f4991b

Please sign in to comment.