Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a file whose extension is .log, though I have this particular file set to open in TextWrangler instead of Console.app (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 Console.app again. Is there any way around this in the script, like setting back the appropriate metadata after the sed line?

share|improve this question
add comment

1 Answer

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
EOF
share|improve this answer
add comment

Your Answer

 
discard

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.