Created
November 24, 2014 00:54
-
-
Save unforswearing/608e8234274ffc359b4f to your computer and use it in GitHub Desktop.
Finder Services Alfred workflow script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on alfred_script(q) | |
# set q to text returned of (display dialog "q" default answer "") | |
# (the above line can be uncommented if you want to use the script as an application or something similar) | |
if q is "read" then | |
# read file | |
tell application "Finder" | |
set ffile to selection as text | |
set ffile to quoted form of POSIX path of ffile | |
set the clipboard to (do shell script "cat " & ffile) | |
end tell | |
return "file read" | |
else if q is "path" then | |
# copy path with \ | |
tell application "Finder" | |
set ffile to selection as text | |
set ffile to quoted form of POSIX path of ffile | |
set the clipboard to (do shell script "echo " & ffile & " | sed 's/ /\\ /g'") | |
return "path copied" | |
end tell | |
else if q is "size" then | |
# get size of finder window | |
tell application "Finder" | |
set bnds to bounds of window 1 | |
end tell | |
return bnds | |
else if q is "qpath" then | |
# get quoted path | |
tell application "Finder" | |
set ffile to selection as text | |
set ffile to quoted form of POSIX path of ffile | |
set the clipboard to ffile | |
end tell | |
return "quoted path copied" | |
else if q is "nvpath" then | |
# copy nv path | |
tell application "Finder" | |
set pathFile to selection as text | |
set pathFile to get POSIX path of pathFile | |
set the clipboard to pathFile | |
set newPath to (do shell script "pbpaste | sed -e 's/ /%20/g'") | |
set the clipboard to "file://" & newPath | |
end tell | |
return "nv path copied" | |
else if q is "label" then | |
# set label to blue | |
tell application "Finder" | |
repeat with f in items of (get selection) | |
set label index of f to 4 | |
end repeat | |
end tell | |
return "blue label added" | |
else if q is "nolable" then | |
# remove label | |
try | |
tell application "Finder" | |
repeat with f in items of (get selection) | |
set label index of f to 0 | |
end repeat | |
end tell | |
end try | |
return "label removed" | |
else if q is "close" then | |
# close all windows | |
tell application "Finder" | |
close every window | |
end tell | |
return "finder windows closed" | |
else if q is "resize" then | |
# resize to set bounds | |
tell application "Finder" | |
set bounds of window 1 to {72, 90, 983, 624} | |
end tell | |
return "finder resized" | |
else if q is "shell" then | |
# open finder directory in terminal | |
tell application "Finder" | |
set go2shell to selection as text | |
set go2shell to quoted form of POSIX path of go2shell | |
if go2shell contains "." then | |
set rmfile to do shell script "basename " & go2shell | |
set go2shell to do shell script "echo " & go2shell & " | sed -e 's/" & rmfile & "//g'" | |
set go2shell to quoted form of go2shell | |
end if | |
tell application "Terminal" | |
activate | |
do script "cd " & go2shell | |
activate | |
end tell | |
end tell | |
return "going to terminal" | |
else if q is "showd" then | |
# show files on the desktop | |
do shell script "defaults write com.apple.finder CreateDesktop -bool true && killall Finder" | |
return "desktop items showing" | |
else if q is "hided" then | |
# hide files on the desktop | |
do shell script "defaults write com.apple.finder CreateDesktop -bool false && killall Finder" | |
return "desktop items hidden" | |
else if q is "showf" then | |
# show hidden files | |
do shell script "defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app" | |
return "hidden files showing" | |
else if q is "hidef" then | |
# rehide hidden files | |
do shell script "defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app" | |
return "hidden files hiding" | |
else if q is "hidewin" then | |
# hide application windows except finder | |
tell application "Finder" | |
set visible of every process whose name is not "Finder" to false | |
end tell | |
return "app windows hidden" | |
else if q is "unhidewin" then | |
# unhide hidden applications | |
tell application "Finder" | |
set visible of every process whose name is not "Finder" to true | |
end tell | |
return "app windows unhidden" | |
else if q is "bright0" then | |
# completely dim screen | |
tell application "System Preferences" | |
activate | |
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" | |
tell application "System Events" | |
delay 1 | |
set value of slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences" to 0 | |
end tell | |
quit | |
end tell | |
return "brightness at 0" | |
else if q is "bright5" then | |
# set screen brightness to 50% | |
tell application "System Preferences" | |
activate | |
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" | |
tell application "System Events" | |
delay 1 | |
set value of slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences" to 0.5 | |
end tell | |
quit | |
end tell | |
return "brightness at half" | |
else if q is "bright1" then | |
# set screen brightness to 100% | |
tell application "System Preferences" | |
activate | |
reveal anchor "displaysDisplayTab" of pane id "com.apple.preference.displays" | |
tell application "System Events" | |
delay 1 | |
set value of slider 1 of group 1 of tab group 1 of window 1 of process "System Preferences" to 1 | |
end tell | |
quit | |
end tell | |
return "brightness at full" | |
else if q is "chmod" then | |
# make selected file executable | |
tell application "Finder" | |
set chmodFile to selection as text | |
set chmodFile to quoted form of POSIX path of chmodFile | |
do shell script "chmod +x " & chmodFile | |
end tell | |
return "file is now executable" | |
else if q is "dock" then | |
# hide or show dock | |
tell application "System Events" | |
tell dock preferences | |
if autohide is false then | |
set autohide to true | |
return "dock is hidden" | |
else if autohide is true then | |
set autohide to false | |
return "dock is visisble" | |
end if | |
end tell | |
end tell | |
(* | |
else if q is "tag" then | |
# tag file with one keyword | |
tell application "Finder" | |
set ffile to selection as text | |
set ffile to quoted form of POSIX path of ffile | |
tell application "Terminal" | |
activate | |
delay 1 | |
do script "tag -a " & tagg & " " & ffile | |
end tell | |
*) | |
end if | |
end alfred_script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This workflow combines (and replaces) several individual scripts I usually use via the Finder toolbar and/or other individual Alfred workflows.
To use, type
fs [option]
Here is the list of options from the help text:
bright0
: set monitor brightness to 0% (completely dim)bright1
: set monitor brightness to 100% (full brightness)bright5
: set monitor brightness to 50%chmod
: make the selected file executable in terminalclose
: close all Finder windowsdock
: show or hide the dockhided
: hide files on the desktophidef
: re-hide hidden fileshidewin
: hide all application windows (except Finder)label
: add a blue label to selected filenolabel
: remove the label from a selected filenvpath
: copy the notational velocity friendly path of the selected filepath
: copy the path of the selected fileqpath
: copy the quoted path of the selected fileread
: read the selected fileresize
: resize the frontmost Finder windowshell
: open the selected files path in terminalshowd
: show files on the desktopshowf
: show hidden filesunhidewin
: unhide all hidden application windows (except Finder)