Skip to content

Instantly share code, notes, and snippets.

@meoow
Last active October 6, 2018 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meoow/c9b07e9272cc73e2bb05fe2b2ab97608 to your computer and use it in GitHub Desktop.
Save meoow/c9b07e9272cc73e2bb05fe2b2ab97608 to your computer and use it in GitHub Desktop.
write text from the clipboard to text file inside path finder or finder's current directory
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
on writeclipdown(filepath)
try
set f to open for access file filepath with write permission
set eof of f to 0
set olddel to AppleScript's text item delimiters
set AppleScript's text item delimiters to {return & linefeed, return, linefeed, character id 8233, character id 8232}
set newText to text items of (get the clipboard)
set AppleScript's text item delimiters to {linefeed}
set newText to newText as text
set AppleScript's text item delimiters to olddel
write newText as «class utf8» to f starting at eof
close access f
return true
on error
try
close access f
end try
return false
end try
end writeclipdown
script writedown
property currFolder : ""
on pathfinder()
try
application id "com.cocoatech.PathFinder"
on error number -1728
return false
end try
tell application id "com.cocoatech.PathFinder"
if it is not running then
return false
end if
set currFolder to (path of target of the front finder window) as alias
log "pathfinder's current folder is " & currFolder
if currFolder is not "" then
return true
else
return false
end if
end tell
end pathfinder
on finder()
tell application id "com.apple.finder"
set currFolder to (target of the front Finder window) as alias
log "finder's current folder is " & currFolder
if currFolder is not "" then
return true
else
return false
end if
end tell
end finder
end script
on run
if writedown's pathfinder() or writedown's finder() then
set newtextfile to (currFolder of writedown as text) & "cliptext.txt"
end if
writeclipdown(newtextfile)
end run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment