Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a file whose extension is .log, though I have this particular file set to open in TextWrangler instead of (using "Open with" in Finder's Get Info panel).

I have a Bash shell script (.sh) that uses SED to replace some text in a file, inline, like so:

sed -i "" "s_find_replace_g" "$FILENAME"

The problem is that after the script runs, the "Open with" association is gone; the file opens with again. Is there any way around this in the script, like setting back the appropriate metadata after the sed line?

share|improve this question
up vote 0 down vote accepted

It's not a "pure" Bash solution, but then, Mac metadata isn't pure Unix either. I am calling AppleScript inline:

sed -i "" "s_find_replace_g" "$FILENAME"

osascript <<-EOF
    set afile to "${FILENAME}"
    set default_app to (path to application "TextWrangler") as text
    tell application "System Events"
        set default application of disk item afile to default_app
    end tell
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.