Skip to content

Instantly share code, notes, and snippets.

@mcskrzypczak
Created May 14, 2013 10:40
Show Gist options
  • Save mcskrzypczak/5575079 to your computer and use it in GitHub Desktop.
Save mcskrzypczak/5575079 to your computer and use it in GitHub Desktop.
The script for Alfred workflow
on run argv
-- translate the Alfred query to text
set sArgv to argv as text
-- prepare some items
set l_Files to {}
set sResult to ""
-- tab indicates multiple files
if sArgv contains tab then
set {TID, text item delimiters} to {text item delimiters, tab}
set l_Files to text items of sArgv
set text item delimiters to TID
else
set end of l_Files to sArgv
end if
-- process the list of files
repeat with j from 1 to (count l_Files)
-- get apple script path
set fileAlias to POSIX file (item j of l_Files) as alias
-- let inside tell only the necessary
tell application "Finder"
set fileName to name of fileAlias
set fileExt to name extension of fileAlias
end tell
-- remove the extension if any
if fileExt is not "" then
set nameLenght to (count of fileName) - (count of fileExt) - 1
set fileName to text 1 thru nameLenght of fileName
end if
-- set result
if (count l_Files) = 1 then
set sResult to fileName
else if j = (count l_Files) then
set sResult to sResult & fileName
else
set sResult to sResult & fileName & ", "
end if
end repeat
-- copy to the clipboard
set the clipboard to sResult as text
-- notification
return ((count l_Files) as text) & " name(s) copied to the clipboard"
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment