使用coffeescript

问题描述

我一直在MacBook上使用Übersicht在桌面上安装小部件。这些小部件可自定义,修改其CoffeeScript文件。我有一个小部件,可以显示计算机的RAM内存统计信息。我添加了一个按钮,因为我想在终端上运行以下命令:

sudo purge

但是我不知道如何在CoffeeScript上执行此操作,因为我对此很陌生。我还使用上面编写的命令创建了一个shell命令文件,但是我不知道下一步是如何从我的小部件中运行它。但是我还有另一个问题:为了运行该命令,我需要输入密码,但是我不知道如何使它在shell命令文件中自动运行,然后在完成该过程后关闭终端。 / p>

这是我的小部件代码:

command: "memory_pressure && sysctl -n hw.memsize"

refreshFrequency: 2000

style: """

  bar-height = 6px
  widget-align = left
  top 587px
  left 293px
  color #fff
  font-family Helvetica Neue
  background rgba(#088FA8,.8)
  padding 0px 10px 15px
  border-radius 5px

  .container
    width: 248px
    text-align: widget-align
    position: relative
    clear: both

  .widget-title
    text-align: widget-align
    padding-top: 10px

  .stats-container
    margin-bottom 5px
    border-collapse collapse

  .btn-style 
    background-color: Transparent
    width: 20px;
    height: 20px;
    border: none
    cursor:pointer
    color: white
    font-family Helvetica Neue
    font-size 10px
    text-transform uppercase
    font-weight 400
    border-radius 5px
    transition-duration: 0.2s

  .btn-style:hover
    background-color: #29A8B6
    color: white;
    box-shadow: 0 8px 16px 0 rgba(0,0.2),0 6px 20px 0 rgba(0,0.19)

  td
    font-size: 14px
    font-weight: 100
    color: rgba(#fff,.9)
    text-align: widget-align

  .widget-title
    font-size 10px
    text-transform uppercase
    font-weight 400
    padding-bottom: 10px

  .label
    font-size: 8px
    text-transform: uppercase
    font-weight: 400
    letter-spacing: 0.3px

  .bar-container
    width: 100%
    height: bar-height
    border-radius: bar-height
    float: widget-align
    clear: both
    background: rgba(#fff,.5)
    position: absolute
    margin-bottom: 5px

  .bar
    height: bar-height
    float: widget-align
    transition: width .2s ease-in-out

  .bar:first-child
    if widget-align == left
      border-radius: bar-height 0 0 bar-height
    else
      border-radius: 0 bar-height bar-height 0

  .bar:last-child
    if widget-align == right
      border-radius: bar-height 0 0 bar-height
    else
      border-radius: 0 bar-height bar-height 0

  .bar-inactive
    background: rgba(#0bf,.5)

  .bar-active
    background: rgba(#fc0,.5)

  .bar-wired
    background: rgba(#c00,.5)
"""

render: -> """
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

    <div class="container">
    <table width="100%">
      <tr>
        <td class="widget-title">Memory</td>
        <td style="text-align: right">
          <button class="btn-style">
            <i class="fa fa-refresh"></i>
          </button>
        </td>
      </tr>
    </table>
    <table class="stats-container" width="100%">
      <tr>
        <td class="stat"><span class="wired"></span></td>
        <td class="stat"><span class="active"></span></td>
        <td class="stat"><span class="inactive"></span></td>
        <td class="stat"><span class="free"></span></td>
        <td class="stat"><span class="total"></span></td>
      </tr>
      <tr>
        <td class="label">wired</td>
        <td class="label">active</td>
        <td class="label">inactive</td>
        <td class="label">free</td>
        <td class="label">total</td>
      </tr>
    </table>
    <div class="bar-container">
      <div class="bar bar-wired"></div>
      <div class="bar bar-active"></div>
      <div class="bar bar-inactive"></div>
    </div>  
  </div>
"""

update: (output,domEl) ->

  usage = (pages) ->
    mb = (pages * 4096) / 1024 / 1024
    usageFormat mb

  usageFormat = (mb) ->
    if mb > 1024
      gb = mb / 1024
      "#{parseFloat(gb.toFixed(1))}GB"
    else
      "#{parseFloat(mb.toFixed())}MB"

  updateStat = (sel,usedPages,totalBytes) ->
    usedBytes = usedPages * 4096
    percent = (usedBytes / totalBytes * 100).toFixed(1) + "%"
    $(domEl).find(".#{sel}").text usage(usedPages)
    $(domEl).find(".bar-#{sel}").css "width",percent

  lines = output.split "\n"

  freePages = lines[3].split(": ")[1]
  inactivePages = lines[13].split(": ")[1]
  activePages = lines[12].split(": ")[1]
  wiredPages = lines[16].split(": ")[1]

  totalBytes = lines[28]
  $(domEl).find(".total").text usageFormat(totalBytes / 1024 / 1024)

  updateStat 'free',freePages,totalBytes
  updateStat 'active',activePages,totalBytes
  updateStat 'inactive',inactivePages,totalBytes
  updateStat 'wired',wiredPages,totalBytes

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...