News for hackers. Stuff that matters.
Re:Vim Anywhere by jxy on Friday February 16, 2018 @03:52PM (#16396090)
I have an Automator workflow script, which uses emacsclient to edit any text, in my `~/Library/Services`. The service receives selected text in any application and output replaces the selected text. It consists of two parts: Run AppleScript, and Run Shell Script.

The AppleScript part is:

    on run {input, parameters}	
    	tell application "EmacsMac" to activate
    	tell application "System Events"
    		repeat until visible of process "Emacs" is true
    			delay 0.5
    		end repeat
    	end tell
    	return input
    end run
and the Shell Script part (pass input to stdin) is:

    tmp=$(mktemp "$HOME/tmp/EditTextinEmacsXXXXXXXX")
    ec=/Applications/MacPorts/EmacsMac.app/Contents/MacOS/bin/emacsclient
    cat > "$tmp"
    until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do
      sleep 1
    done
    $ec -q -c "$tmp"
    rv="$?"
    cat "$tmp"
    if [ $rv -ne 0 ]; then
      echo "Something went wrong.  Please find your text in"
      echo "$tmp"
    else
      rm "$tmp"
    fi
Getting it to work with any editor should be straightforward.
Re:Vim Anywhere by d1egoaz on Friday February 16, 2018 @05:14PM (#16396951)
Wow, this is awesome!

Is there any way to make it work without selecting text? (default to all available text on the textarea)

BTW, I changed a few things: emacsclient path and the tmp folder:

  tmp=$(mktemp "/tmp/EditTextinEmacsXXXXXXXX")
  ec=/usr/local/bin/emacsclient
  cat > "$tmp"
  until [ $($ec -q -e '(server-running-p)' 2>/dev/null) == t ]; do
    sleep 1
  done
  $ec -q -c "$tmp"
  rv="$?"
  cat "$tmp"
  if [ $rv -ne 0 ]; then
    echo "Something went wrong.  Please find your text in"
    echo "$tmp"
  else
    rm "$tmp"
  fi
Re:Vim Anywhere by d1egoaz on Tuesday February 20, 2018 @07:30PM (#16425705)
I ended forking and creating this https://github.com/d1egoaz/vim-anywhere WIP
Re:Vim Anywhere by swsieber on Friday February 16, 2018 @06:36PM (#16397606)
Hmm... I'm not very familiar with this, but couldn't you send a key command to select the entire text (CMD A)?
Re:Vim Anywhere by d1egoaz on Friday February 16, 2018 @06:42PM (#16397646)
I'm not very familiar either. But the Automator workflow starts with "receives selected text", so I'm not sure it has access to the current text field
Re:Vim Anywhere by swsieber on Saturday February 17, 2018 @02:40AM (#16399566)
Did not know that. I've used HammerSpoon on Mac, and you can send key shortcuts with that... you could probably glue them together easily
Re:Vim Anywhere by d1egoaz on Tuesday February 20, 2018 @07:31PM (#16425709)
osascript is our friend

    osascript -e 'tell application "System Events" to keystroke "a" using command down'
Re:Vim Anywhere by jiqiren on Saturday February 17, 2018 @01:16AM (#16399349)
why not "mktemp -t EditTextinEmacs". This will touch a file in $TMPDIR which is more safe than /tmp.