Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I resolve an alias in Mac OS X?

Status
Not open for further replies.

georgeocrawford

Technical User
Aug 12, 2002
111
GB
Hi,

Running OS X 10.3.

I've written a php script, including a few shell commands, which searches a directory recursively, and record the paths of each file and directory it comes across in a MySQL database.

This enables me to generate a web-based 'directory browser', with each folder displayed as a hyperlink to the contents of that directory (similar to the indexing system Apache can employ when there is no index.html file in a directory, for example).

I understand from my research that OS X's aliases (i.e. the Finder-based shortcut, not symbolic links) are a complicated affair. Ideally, I would like my script to detect an alias during the scan, and add a note into the database that this folder should actually link to the contents of another folder.

How can I:

a) detect that a file is an ailas?
b) resolve the full path of the alias's target file/directory?

I need to be able to do this from within PHP, but using shell calls I can do anything that could normally be typed into the Terminal.

Any help would be appreciated!

______________________

George
 
If I run:

Code:
die(shell_exec('aliascheck /path/to/an/alias/file 2>&1'));

in a php script, it prints:

Code:
INIT_Processeses(), could not establish the default connection to the WindowServer.[code]

I'm running OS X 10.3.

Can someone please help me???????

______________________

George
 
Ok - getting there.

Can someone help me optimize this please:

Code:
count=0
while read line; do
        count=$(( count + 1 ))
        item_path="/Library/WebServer/Documents/"$line
        linksource=`osascript<<EOS
          tell app &quot;Finder&quot;
            set theItem to (POSIX file &quot;${item_path}&quot;) as alias
             if the kind of theItem is &quot;alias&quot; then
             get the posix path of (original item of theItem as text)
            end if
          end tell
          EOS`
    if [ $? -eq 0 ]; then
      if [ ! -z &quot;$linksource&quot; ]; then
        echo $item_path' => '$linksource
      fi
    fi
done < /Library/WebServer/Documents/test_folder/filelist.txt

which is performed on a list of files in filelist.txt.

This script will be run as a cron job.

I need to try and speed this up. I know that the Apple aliases I'm dealing with will have a very small filesize - normally 0 bytes as the info is in the resource fork - and that they all have a tag - '[A]' - in the filename (such as document[A].txt).

How can I add this condition before the AppleScript call?

Thanks!

______________________

George
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top