current timeをhh:mm:ssで表示する方法。

Current dateで時間を尋ねると、8:58:46のように表示されますよね。

しかしCurren timeで時間を尋ねると、秒数か何かで表示されますよね。

これをhh:mm:ss形式に直すスクリプトを教えていただけませんか?

Quick time 7の現在の再生時間をhh:mm:ssで表示させたいのですが、

tell application "QuickTime Player 7" to get current time of document 1

このスクリプトだと、秒数表示になってしまいます。

Mac mini, OS X Mountain Lion (10.8.2)

投稿日 2013/04/02 17:11

返信
返信: 17

2013/04/02 22:18 akanejapan への返信

すみません。 勘違いしていました。 動画再生の経過時間についての表示ですね。 以下のハンドラーはどうでしょうか? my theTime(current time) で呼び出します。



on theTime(t)


set h to round (t / (60 * 60)) rounding down

set m to (round (t / 60) rounding down) - 60 * h

set s to round (t mod 60) rounding down

set Str to (1000000 + h * 10000 + m + 100 + s) as string


tell Str to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7


end theTime

2013/04/03 02:10 T22T への返信

御回答有り難うございます。申し訳ありませんが、”my”をつかったことがないので、記述法がよくわからないので、補足いただけないでしょうか?

下記に、実行して失敗したものと、エラー内容を載せておきます。


tell application "QuickTime Player 7"

my theTime(current time) of document 1

end tell


on theTime(t)


set h to round (t / (60 * 60)) rounding down

set m to (round (t / 60) rounding down) - 60 * h

set s to round (t mod 60) rounding down

set Str to (1000000 + h * 10000 + m + 100 + s) as string


tell Str to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7


end theTime



tell application "QuickTime Player 7"

get current time


--> error number -1728 from current time

結果:

error "QuickTime Player 7 でエラーが起きました:current time を取り出すことはできません。" number -1728 from current time

2013/04/03 02:27 akanejapan への返信

度々、失礼致します。

tell application "QuickTime Player 7"

my theTime(current time) of document 1

end tell

この部分を

tell application "QuickTime Player 7"

tell document 1

my theTime(current time)

end tell

end tell


あるいは、

tell document 1 of application "QuickTime Player 7"

my theTime(current time)

end tell


とすれば作動すると考えます。 どうでしょうか?

2013/04/03 05:25 T22T への返信

かなりおしいところまできてると思うですが、最初の秒数の取得がうまくいっていないようです。

秒数が莫大な数字になっているので、ミリ秒のその先のその先くらいまで取得している気がします。

以下は、開始約23秒のところで情報を取得した結果ですが、最初の秒が2087760になってしまっています。汗


tell application "QuickTime Player 7"


tell document 1


my theTime(current time)


end tell


end tell




on theTime(t)


set h to round (t / (60 * 60)) rounding down

set m to (round (t / 60) rounding down) - 60 * h

set s to round (t mod 60) rounding down

set Str to (1000000 + h * 10000 + m * 100 + s) as string

tellStrtotext 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7


end theTime


tell application "QuickTime Player 7"

get current time of document 1


--> 2087760

end tell

tell current application

round 579.933333333333 rounding down


--> 579

round 3.4796E+4 rounding down


--> 34796

round 0 roundingdown


--> 0

end tell

結果:

"79:56:00"

2013/04/03 05:53 akanejapan への返信

QuickTime Player 7 は time scale が 600 なので、current time の戻り値を 600 で割れば上手く行くと思います。


で、こんな感じでどうでしょうか?(ついてにサブルーチンを整理整頓しました。)ちなみに、QuickTime Player X の場合は theTime(t, 1) とすると良いでしょう。


on run

tell application "QuickTime Player 7"

set t to current time in document 1

end tell

theTime(t, 600)

end run

--

on theTime(t, t_scale)

--

set t to t div t_scale

--

set h to t div 3600

set m to t mod 3600 div 60

set s to t mod 3600 mod 60

--

set Str to (1000000 + h * 10000 + m * 100 + s) as string

--

tell Str to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7

--

end theTime

2013/04/03 06:07 Hiro__S への返信

Hiro.Sさん、有り難うございます。 私は、QuickTime Player(ver.10.2)の辞書を参照して、documentクラスのcurrent timeのPropertiesの説明には、『 current time (real) : The current time of the movie in seconds. 』とあるので、current timeが返す値の単位は秒になっているものと考えてしまいました。 QuickTime Player 7の場合と異なるという事ですね。 akanejapanさん、勘違いをもとに書き込んでしまいました。 済みませんでした。

2013/04/03 06:15 Hiro__S への返信

ありがとうございます。ほぼこれで解決できたようです。

一つ気づいたのは音楽ファイルと映像ファイルでcurrent timeの処理が違うということに気づきました。

音声の場合は

theTime(t, 600)で取得できますが、

映像(m4v)の場合は

theTime(t, 90000)でないとうまくhh:mm:ssに変換されないようです。

90000というのは、いろいろ数値変えてみた結果だしたものですので、なぜ、90000にするとうまくいくのかはよくわかっていません(汗

このスレッドはシステム、またはAppleコミュニティチームによってロックされました。 問題解決の参考になる情報であれば、どの投稿にでも投票いただけます。またコミュニティで他の回答を検索することもできます。

current timeをhh:mm:ssで表示する方法。

Apple サポートコミュニティへようこそ
Apple ユーザ同士でお使いの製品について助け合うフォーラムです。Apple Account を使ってご参加ください。