Home >

Requirements

Download

Version 1.7 -- 2017-04-14

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 and shell commnads. 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 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.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