Home > XModules >

Requirements

  • OS X 10.9 or later
    • Developed and tested on macOS 10.14.6

Download

Version 1.8.4 -- 2020-04-17

Old Versions

Dependencies

XFile

XFile provides unified object oriented interface to file operation (moving, removing, geting attributes and so on).

Functions of file operations of AppleScript world is given by Scrpting Additions, Finder, System Events, shell commnads and Cocoa thru AppleScriptObjC. It is cumbersome to find a proper way, because implemeted locations of functions are distributed. XFile wraps these components and introduces a file object for unified object oriented interface.

use XFile : script "XFile"
use scripting additions

(* Make a New Instance *)
set a_xfile to XFile's make_with("/Users")
set home_folder to XFile's make_with(path to home folder)

(* Obtain File Infomation *)
log a_xfile's type_identifier() -- "public.folder"
log a_xfile's is_folder() -- true
log a_xfile's is_package() -- false
log a_xfile's item_name() -- "Users"

(* Obtain Parent and Child *)
log home_folder's parent_folder()'s posix_path()
-- "/Users"
log home_folder's child("Documents")'s posix_path()
-- "/Users/yourhome/Documents"
log home_folder's child("Library/Scripts")'s posix_path()
-- "/Users/yourhome/Library/Scripts"
log home_folder's unique_child("Documents")'s posix_path()
--"/Users/yourhome/Documents 2"

(* Read and Write *)
set test_file to home_folder's child("testfile")
test_file's write_as_utf8("new data")
log test_file's read_as_utf8() -- "new data"

(* File Manipulations *)
log test_file's item_exists() --true

set test_file2 to test_file's copy_to(home_folder's child("testfile2"))
log test_file2's posix_path() -- "/Users/yourhome/testfile2"

test_file2's move_to(home_folder's child("Documents"))
log test_file2's posix_path() -- "/Users/yourhome/Documents/testfile2"

test_file2's into_trash()
log test_file2's posix_path() -- "/Users/yourhome/.Trash/testfile2"
test_file's into_trash()

(* Working with Shell Commands *)
log test_file's perform_shell("cat %s") -- "new data"

History

  • 1.8.4 -- 2020-04-17
    • Added is_executable().
  • 1.8.3 -- 2020-03-18
    • Fixed : a XFile instance did not follow the destination after a file is moved with move_with_replacing.
  • 1.8.2 -- 2020-02-26
    • Use NSFileManager for list_children() instead of scripting additions's list folder command.
  • 1.8.1 -- 2020-02-05
    • Added copy_with_replacing
    • copy_to is reimplemented using NSFileMangaer.
    • copy_to don't replace a copy destination.
    • is_folder returns ture for disks.
    • Fixed error of move_with_replacing.
  • 1.8 -- 2020-02-04
    • resolve_alias is reimplemented using NSURL.
    • remove, move_to, move_with_replacing, into_trash are reimplemented using NSFileManager.
    • Fixed is_package()
    • PathInfo 1.3.1 or later is required.
  • 1.7.2 -- 2020-02-03
    • Added type_identifier()
    • is_folder, is_alias, is_symlink, is_package are reimplemented using type_ideintifier().
    • Fixed the problems of into_trash() due to alias values in macOS 10.14 don't follow changing location.
  • 1.7.1 -- 2020-01-28
    • Use OpenHelpBook.scptd instead of HelpBook.osax.
    • Fixed the problems of move_to() due to alias values in macOS 10.14 don't follow changing name and location.
  • 1.7 -- 2017-04-14
    • Enabled to work with AppleScript Libraries.
    • Removed dependency on ModuleLoader.
    • OS X 10.9 or later is required.
    • Updated the help book.
  • 1.6 -- 2015-09-04
    • Added "move_with_replacing".
    • Added "volume_name".
  • 1.5 -- 2012-06-01
    • Added "info_with_size".
    • Added "perform_shell".
    • Added "shell_test"
    • Added "is_symlink"
    • The file infomation returned from "info" will not contain size infomation.
    • "resolve_alias" can follow the origianl of symbolics.
    • Improved perfomance of "copy_to" and "copy_with_opts".
  • 1.4 -- 2012-05-26
    • Added "normalized_posix_path".
    • Added "item_exists_without_update".
    • Added "each".
  • 1.3.3 -- 2011-02-10
    • Fixed resolve_alias().
    • Fixed is_folder(). Use a result of info for command.
  • 1.3.2 -- 2010-09-09
    • Refixed unique_child() for a name without including path extenstion.
  • 1.3.1 -- 2010-06-16
    • Fixed unique_child() for the instance created from a HFS path.
    • Fixed unique_child() for a name without including path extenstion.
  • 1.3 -- 2010-03-25
    • ModuleLoader is needed to load XFile.
    • Using PathInfo instead of PathAnalyzer.
    • Removed dependency on ShowHelpBook.
    • make_with() accepts POSIX pathes.
    • Added make_with_pathinfo().
    • Removed make_with_record().
    • Removed folder_name.
    • A POSX path must be passed to child(), make_folder(), make_path() instead of a HFS path.
    • Added copy_with_opts().
    • copy_to and copy_with_opts can accept a relative path as a destination.
    • Added as_furl().
    • make_path() have an argument.
  • 1.2.2 -- 2009-11-09
    • remove() will return a reviever instance.
    • copy_to will preserve file attirbutes(e.g. modification/creation date, etc).
  • 1.2.1 -- 2009-03-09
    • Fix Japanese manual can't displayed in Help Viewer.
  • 1.2 -- 2009-02-18
    • Improve unique_child() in Mac OS X 10.5
    • Remove dependency on UniqueNamer.
  • 1.1.2 -- 2009-01-29
    • item_exists() cause to reconstruct the inner file reference of alias class.
  • 1.1.1 -- 2008-11-03
    • item_exists() always access filesystem to check existantce.
    • Improve compatibility with Mac OS X 10.5 with PathAnalyzer 1.7.1.
  • 1.1 -- 2008-03-20
    • reimplement move_to method using mv command.
    • move_to method returns a boolean value.
    • fix mistakes in the manual.
  • 1.0 -- 2007.08.15
    • First release