Skip to content

Commit

Permalink
Create fileish.scpt
Browse files Browse the repository at this point in the history
Study for issue #1
  • Loading branch information
doekman committed Feb 18, 2020
1 parent a0a2139 commit 4408dd0
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions fileish.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#@osa-lang:AppleScript
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions


script Fileish
-- Current working folder, used to resolve relative path's like "./file.ext"
property working_folder : POSIX path of (path to home folder)

on get_type(fileish_specifier)
if class of fileish_specifier is text then
if fileish_specifier starts with "/" then
return "posix_abs_path"
else if fileish_specifier starts with "./" or fileish_specifier starts with "~/" then
return "posix_rel_path"
end if
else if class of fileish_specifier is alias then
return "alias"
else if class of fileish_specifier is file then
return "file"
else if class of fileish_specifier is «class furl» then
return "posix_file"
end if
log "Unknown fileish type: " & class of fileish_specifier
return "unknown"
end get_type

on to_posix(fileish_specifier)
local fileish_type
set fileish_type to fileish_get_type(fileish_specifier)

end to_posix

on is_fileish(fileish_specifier)
return fileish_get_type(fileish_specifier) "unknown"
end is_fileish

end script
--set ding to choose file
--set ding to POSIX file "/Users/doeke/prj/GitHub/ASPashua/makefile"
--set ding to "~/prj/GitHub/ASPashua/makefile"
set ding to "./prj/GitHub/ASPashua/makefile"
--set ding to "/Users/doekman/prj/GitHub/ASPashua/makefile"
--get is_fileish(ding)
set working_folder of Fileish to "/Users/doeke/Downloads/intranet"
get working_folder of Fileish

0 comments on commit 4408dd0

Please sign in to comment.