Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

From alias to real file

Is there a way to turn a folder with aliasses (in this case a burn-folder) into a folder with (copies of) the real files in it.

When I start a new project (as an architect) I make a folder with reference material (aliasses) that most of the time only has to exist as long as the project is running. After that I throw the folder away and evrything stayes in its place.
But sometimes I want to take all that aliassed material to someone else and therefor I need to gather it in a folder.

I'm an absolute novice in Applescript and folder-actions.

PowerMac G5 (2x1.8) double harddisk, Mac OS X (10.4.11)

Posted on Jun 16, 2008 3:32 AM

Reply
Question marked as Best reply

Posted on Jun 16, 2008 4:58 AM

Hardwired solution:

-- Code starts here --

set fPath to "HD01:Users:d:Desktop:_TestBed01:" -- Full path of folder to process.

tell application "Finder" -- Focus on 'Finder' commands.

try -- Capture, and ignore, any AppleScript error(s).
set aItems to every file of folder fPath whose kind is "Alias" -- Obtain list of all alias' files.
set tContainer to container of (item 1 of aItems) -- Path of alias containing folder.

-- Obtain list of all (alias referenced) original files.
set oItems to original item of every file of folder fPath whose kind is "Alias"

delete aItems -- Delete 'alias' files.
duplicate oItems to tContainer -- Duplicate original files into container folder of deleted alias'es.

empty trash -- Empty the trash can.
end try

end tell

-- Code ends here --

Save the above code as a script (for execution via 'Script Editor', or the 'Script Menu' - if enabled); or, as an application (AppleScript 'applet') - which when double clicked on, is executed..

---

Dynamically selected solution:

-- Code starts here --

on run {} -- Execute, if applet was double clicked on.
my handle_Files((choose folder with multiple selections allowed) as list)
end run

on open (dItems) -- Execute, if a folder was, or folders were, dragged onto applet.
my handle_Files(dItems)
end open

on handle_Files(tItems)
with timeout of 0 seconds -- Allows an infinite length of time to process.
tell application "Finder" -- Focus on 'Finder' commands.

repeat with i in tItems -- Cycle through selected, or dragged on, items.

if ((kind of i) is "Folder") then -- Process only folder.
try -- Capture, and ignore, any AppleScript error(s).
set aItems to (every file of folder i whose kind is "Alias") -- Obtain list of all alias' files.
set tContainer to container of (item 1 of aItems) -- Path of alias containing folder.

-- Obtain list of all (alias referenced) original files.
set oItems to (original item of every file of folder i whose kind is "Alias")

delete aItems -- Delete 'alias' files.
duplicate oItems to tContainer -- Duplicate original files into container folder of deleted alias'es.

empty trash -- Empty the trash can.
end try
end if

end repeat

end tell
end timeout
end handle_Files

-- Code ends here --

Save the above code as an application (AppleScript 'applet'). One can then double click on the applet - and select the desired folder(s) to process; or drag (a) folder(s) onto the applet, for processing.
7 replies
Question marked as Best reply

Jun 16, 2008 4:58 AM in response to Gerrit Velthuis

Hardwired solution:

-- Code starts here --

set fPath to "HD01:Users:d:Desktop:_TestBed01:" -- Full path of folder to process.

tell application "Finder" -- Focus on 'Finder' commands.

try -- Capture, and ignore, any AppleScript error(s).
set aItems to every file of folder fPath whose kind is "Alias" -- Obtain list of all alias' files.
set tContainer to container of (item 1 of aItems) -- Path of alias containing folder.

-- Obtain list of all (alias referenced) original files.
set oItems to original item of every file of folder fPath whose kind is "Alias"

delete aItems -- Delete 'alias' files.
duplicate oItems to tContainer -- Duplicate original files into container folder of deleted alias'es.

empty trash -- Empty the trash can.
end try

end tell

-- Code ends here --

Save the above code as a script (for execution via 'Script Editor', or the 'Script Menu' - if enabled); or, as an application (AppleScript 'applet') - which when double clicked on, is executed..

---

Dynamically selected solution:

-- Code starts here --

on run {} -- Execute, if applet was double clicked on.
my handle_Files((choose folder with multiple selections allowed) as list)
end run

on open (dItems) -- Execute, if a folder was, or folders were, dragged onto applet.
my handle_Files(dItems)
end open

on handle_Files(tItems)
with timeout of 0 seconds -- Allows an infinite length of time to process.
tell application "Finder" -- Focus on 'Finder' commands.

repeat with i in tItems -- Cycle through selected, or dragged on, items.

if ((kind of i) is "Folder") then -- Process only folder.
try -- Capture, and ignore, any AppleScript error(s).
set aItems to (every file of folder i whose kind is "Alias") -- Obtain list of all alias' files.
set tContainer to container of (item 1 of aItems) -- Path of alias containing folder.

-- Obtain list of all (alias referenced) original files.
set oItems to (original item of every file of folder i whose kind is "Alias")

delete aItems -- Delete 'alias' files.
duplicate oItems to tContainer -- Duplicate original files into container folder of deleted alias'es.

empty trash -- Empty the trash can.
end try
end if

end repeat

end tell
end timeout
end handle_Files

-- Code ends here --

Save the above code as an application (AppleScript 'applet'). One can then double click on the applet - and select the desired folder(s) to process; or drag (a) folder(s) onto the applet, for processing.

Jun 16, 2008 7:49 AM in response to dev_sleidy

Great, the first one does exactly what I want (after I found out that I had to change the path name of the target-folder in the script; I told you I was a novice; probably even less than that).
But I'd prefer the second option which, however, I can't get to work.
I don't think, I have to adjust this script to my situation (or am I wrong).

After double-clicking the applet, it asks for a folder to process, but after choosing one, nothing happens.

Jun 16, 2008 8:43 AM in response to Gerrit Velthuis

'... after I found out that I had to change the path name of the target-folder in the script' - which is why most programmers / script'ers will place variables (such as 'set fPath to "HD01:Users:d:Desktop:_TestBed01:" -- Full path of folder to process') to be (user) edited, at the top of the code.

'I don't think, I have to adjust this script to my situation (or am I wrong). - there is nothing to adjust, in the second code segment.

'After double-clicking the applet, it asks for a folder to process, but after choosing one, nothing happens.' - You have to select the folder(s) with 'alias'es in them - such as the 'burn folder' (of alias'es) you referenced in your original post.

Note: alias'es have a curved arrow (stolen from MS Windoze*) at the icons' lower left. Once the 'alias' containing folder(s) is / are selected - each 'alias' file is deleted and replaced with a copy of the original item (file or folder). So, if you are not looking carefully - you may not have notice the replacement of the 'alias' file, with the original item.

--

* - As Apple slowly destroys the soul of the Macintosh OS (which peaked with 'System 9.2.2'), as it slowly becomes more and more Windoze like - in its inconsistency, pisss poor user experience, and no longer friendly graphical user interface - all, for the purpose of enticing Windoze'rs to purchase Macs.

Jun 16, 2008 9:30 AM in response to dev_sleidy

dev_sleidy wrote:
'... after I found out that I had to change the path name of the target-folder in the script' - which is why most programmers / script'ers will place variables (such as 'set fPath to "HD01:Users:d:Desktop:_TestBed01:" -- Full path of folder to process') to be (user) edited, at the top of the code.

'I don't think, I have to adjust this script to my situation (or am I wrong). - there is nothing to adjust, in the second code segment.

'After double-clicking the applet, it asks for a folder to process, but after choosing one, nothing happens.' - You have to select the folder(s) with 'alias'es in them - such as the 'burn folder' (of alias'es) you referenced in your original post.

Note: alias'es have a curved arrow (stolen from MS Windoze*) at the icons' lower left. Once the 'alias' containing folder(s) is / are selected - each 'alias' file is deleted and replaced with a copy of the original item (file or folder). So, if you are not looking carefully - you may not have notice the replacement of the 'alias' file, with the original item.

--

* - As Apple slowly destroys the soul of the Macintosh OS (which peaked with 'System 9.2.2'), as it slowly becomes more and more Windoze like - in its inconsistency, pisss poor user experience, and no longer friendly graphical user interface - all, for the purpose of enticing Windoze'rs to purchase Macs.

+'After double-clicking the applet, it asks for a folder to process, but after choosing one, nothing happens.' - You have to select the folder(s) with 'alias'es in them - such as the 'burn folder' (of alias'es) you referenced in your original post.+

That's exactly what I did; I made a folder; dropped in some alias'es and tried the second option (copy/pasted the code into Scripteditor;compiled it and saved it as an app) it asks for a folder; chose the one with the alias'es; nothing happens to them.
After that I used the first one (also saved as an app) and the (same) alias'es are immediately replaced by their originals.

btw. the apps have different icons (the one that works looks like a curled piece of paper on a square) the one that doesn't is the same, but has a blue downward arrow added to it.

Jun 18, 2008 5:48 AM in response to Gerrit Velthuis

I'm sorry, dev_sleidy, that you didn't react to my last post.
The applescripts you gave me looked very promissing; I hoped, that you would be able to find out whether I did something wrong with the second, "dynamic solution" or that the script has an error.

The first script works fine, but to make it work, I have to adjust the script (or the foldername) each time I use it. Therefor I'd prefer the second one.

Jun 18, 2008 7:44 AM in response to Gerrit Velthuis

Hello Gerrit Velthuis,

I don't know why dev_sleidy's second script fails you.
It works here with AppleScript 1.8.3 under OS9.1 if I make two minor modifications for backward compatibility. Specifically I removed 'with multiple selections allowed' parameter from 'choose folder' command, for it was introduced in AS1.9.2. Also removed 'with timeout of 0 seconds' statement, for value 0 has literal meaning in AS1.8.3, i.e. it times out instantly. However, since you're using OSX10.4.11, I think the script should work without any modifications.

In case, try removing try block, i.e. removing the two lines - 'try' and 'end try' - to see any possible error message that might occur. Also try removing 'with timeout of 0 seconds' and 'end timeout' statements for similar reason.

---
Also here's another script you may try.
Good luck,
H

--SCRIPT
on run
--main((choose folder with multiple selections allowed) as list)
main((choose folder) as list)
end run

on open aa
main(aa)
end open

on main(aa)
-- confirmation for safety
set AppleScript's text item delimiters to {ASCII character 0}
set aa to (aa as Unicode text)'s text items
set AppleScript's text item delimiters to {""}
set aa to (choose from list aa default items aa ¬
with prompt ("You're replacing alias files in following folder(s).") ¬
with multiple selections allowed)
if aa = false then error number -128

-- replace every alias file in given folders with its original item
set k to 0
repeat with a in aa
set a to a as alias
tell application "Finder"
tell item a
if its class is folder then
tell alias files
set rr to original item
delete
end tell
duplicate rr to it
set k to k + (count rr)
end if
end tell
end tell
end repeat
tell application "Finder" to empty trash

-- decent notice
tell application (path to frontmost application as string)
display dialog ("Total of " & k & " alias file(s) replaced successfully.") ¬
with icon 1 giving up after 5
end tell
end main
--END OF SCRIPT

From alias to real file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.