peta
Dec 05, 2009, 02:35 PM
Hi guys (and lads),
I love Path Finder and its advanced features for working with files and folders. But there was one feature I wished myself almost a thousand times ...
Wrapping a selection of files/folders by another folder!
And finally, I came up with short and simple solution for my demand. A AppleScript that shows a input dialog where the user can enter a folder name or a path, and the selected items are moved into this folder, and, for the case the directory doesn't exist yet, it will be created. As a gimmick I added Growl support, where the user gets displayed a short summary about how many files were wrapped, or, for the case an error occured he will be informed about what happened. here are some pictures where you can see the script in action. (Compiled and called via Quicksilver)
http://img204.imageshack.us/img204/2871/bild12z.png
http://img204.imageshack.us/img204/1514/bild13r.png
http://img708.imageshack.us/img708/2263/bild14.png
Source code:
-- PF.WrapSelectionWithFolder.applescript
--
registerWithGrowl()
tell application "Path Finder"
set pfSelectionList to selection
if length of pfSelectionList = 0 then
return
end if
set cwd to (POSIX path of container of first item of pfSelectionList)
set folderName to text returned of ¬
(display dialog cwd ¬
default answer ¬
"Untitled folder" with title "Enter folder name")
set joinedPath to (cwd & "/" & folderName)
if not (exists joinedPath) then
if (do shell script "mkdir " & quoted form of joinedPath) is not equal to "" then
displayGrowlMessage("Error occured", "Folder couldn't be created") of me
return
end if
end if
set listOfWrappedFiles to ""
try
repeat with i in pfSelectionList
set listOfWrappedFiles to (listOfWrappedFiles & name of i & return)
if (do shell script "mv " & quoted form of (POSIX path of i) & " " & quoted form of (joinedPath & "/" & name of i)) is not equal to "" then
error "File '" & (POSIX path of i) & "' couldn't be moved"
end if
end repeat
on error
displayGrowlMessage("Error occured", "Files couldn't be move to target folder") of me
return
end try
displayGrowlMessage("Wrapped " & length of pfSelectionList & " file(s)", listOfWrappedFiles) of me
end tell
on displayGrowlMessage(headline, msg)
tell application "GrowlHelperApp"
notify with name ¬
"DefaultMsg" title ¬
(headline) description ¬
(msg) application name "Path Finder"
end tell
end displayGrowlMessage
on registerWithGrowl()
tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"DefaultMsg"}
set the enabledNotificationsList to ¬
{"DefaultMsg"}
register as application ¬
"Path Finder" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Path Finder"
end tell
end registerWithGrowl
I love Path Finder and its advanced features for working with files and folders. But there was one feature I wished myself almost a thousand times ...
Wrapping a selection of files/folders by another folder!
And finally, I came up with short and simple solution for my demand. A AppleScript that shows a input dialog where the user can enter a folder name or a path, and the selected items are moved into this folder, and, for the case the directory doesn't exist yet, it will be created. As a gimmick I added Growl support, where the user gets displayed a short summary about how many files were wrapped, or, for the case an error occured he will be informed about what happened. here are some pictures where you can see the script in action. (Compiled and called via Quicksilver)
http://img204.imageshack.us/img204/2871/bild12z.png
http://img204.imageshack.us/img204/1514/bild13r.png
http://img708.imageshack.us/img708/2263/bild14.png
Source code:
-- PF.WrapSelectionWithFolder.applescript
--
registerWithGrowl()
tell application "Path Finder"
set pfSelectionList to selection
if length of pfSelectionList = 0 then
return
end if
set cwd to (POSIX path of container of first item of pfSelectionList)
set folderName to text returned of ¬
(display dialog cwd ¬
default answer ¬
"Untitled folder" with title "Enter folder name")
set joinedPath to (cwd & "/" & folderName)
if not (exists joinedPath) then
if (do shell script "mkdir " & quoted form of joinedPath) is not equal to "" then
displayGrowlMessage("Error occured", "Folder couldn't be created") of me
return
end if
end if
set listOfWrappedFiles to ""
try
repeat with i in pfSelectionList
set listOfWrappedFiles to (listOfWrappedFiles & name of i & return)
if (do shell script "mv " & quoted form of (POSIX path of i) & " " & quoted form of (joinedPath & "/" & name of i)) is not equal to "" then
error "File '" & (POSIX path of i) & "' couldn't be moved"
end if
end repeat
on error
displayGrowlMessage("Error occured", "Files couldn't be move to target folder") of me
return
end try
displayGrowlMessage("Wrapped " & length of pfSelectionList & " file(s)", listOfWrappedFiles) of me
end tell
on displayGrowlMessage(headline, msg)
tell application "GrowlHelperApp"
notify with name ¬
"DefaultMsg" title ¬
(headline) description ¬
(msg) application name "Path Finder"
end tell
end displayGrowlMessage
on registerWithGrowl()
tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"DefaultMsg"}
set the enabledNotificationsList to ¬
{"DefaultMsg"}
register as application ¬
"Path Finder" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "Path Finder"
end tell
end registerWithGrowl